Chat model for Amazon Nova Sonic bidirectional streaming.
This provides a LangChain integration for Amazon Nova Sonic's
bidirectional streaming API (InvokeModelWithBidirectionalStream).
Nova Sonic enables real-time speech-to-speech conversations over a
persistent, full-duplex streaming connection. Unlike the Converse API
used by :class:ChatBedrockConverse, this maintains a persistent
full-duplex connection for continuous audio streaming.
This integration requires the aws-sdk-bedrock-runtime package
which is under active development. Install with:
pip install "langchain-aws[nova-sonic]"
For simple text interactions, use :meth:ainvoke or :meth:astream.
For full audio streaming, use :meth:create_session to get a
:class:NovaSonicSession.
Quick start::
import asyncio
from langchain_aws.chat_models.bedrock_nova_sonic import ChatBedrockNovaSonic
model = ChatBedrockNovaSonic(
model_id="amazon.nova-sonic-v1:0",
region_name="us-east-1",
)
# Text-only conversation
response = asyncio.run(
model.ainvoke("Hello, how are you?")
)
print(response.content)
Audio streaming::
import asyncio
from langchain_aws.chat_models.bedrock_nova_sonic import (
ChatBedrockNovaSonic,
NovaSonicSession,
)
async def stream_audio():
model = ChatBedrockNovaSonic(
model_id="amazon.nova-sonic-v1:0",
region_name="us-east-1",
voice_id="matthew",
)
async with model.create_session() as session:
# Send audio chunks
await session.send_audio_chunk(audio_bytes)
# Receive responses
async for event in session.receive_events():
if event["type"] == "audio":
play(event["audio"])
elif event["type"] == "text":
print(event["text"])
asyncio.run(stream_audio())
| Name | Type | Description |
|---|---|---|
model_id* | unknown | |
region_name* | unknown | |
voice_id* | unknown | |
system_prompt* | unknown | |
max_tokens* | unknown | |
temperature* | unknown | |
top_p* | unknown |
Top-p sampling parameter. |
input_sample_rate* | unknown | Sample rate for input audio in Hz. |
output_sample_rate* | unknown | Sample rate for output audio in Hz. |
The Nova Sonic model identifier.
AWS region for the Bedrock endpoint.
Voice identifier for audio output.
Default system prompt for sessions.
Maximum tokens for inference.
Sampling temperature.
Validate that the Nova Sonic SDK is installed and create client.
Create a bidirectional streaming session.
Use as an async context manager. The session is automatically started and ended.