Nova Sonic 语音对话接入要点
LiveKit 的 AWS 插件可接入 Nova Sonic 双向音频流式语音模型,实现实时语音对话。文档说明了安装方式、内置 VAD 轮次检测的灵敏度档位、文本触发回复的接口以及函数工具的注册与结果回传格式。
LiveKit 文档 › 构建智能体 › 合作伙伴聚焦 › AWS › Amazon Nova Sonic --- # Amazon Nova Sonic 整合指南 > 如何与LiveKit Agents使用亚马逊Nova Sonic模型. 可在下列网址查阅: - [ ] 节点.js - [x] Python 键 ## 概览 亚马逊 [Nova 音响](https://aws.amazon.com/ai/generative-ai/nova/speech/) 是一种state-of-the-art speech-to-speech型号,双向音频流传着API. Nova Sonic进程,并随其发生而响应实时语音,使得自然,人样的对话体验成为可能. LiveKit的AWS插件包括支持Nova Sonic 1.0,Nova Sonic 2.0,以及Nova Sonic 2.5在AWS Bedrock上的插件. ### 安装 从 PyPI 安装 AWS 插件 `realtime` 额外 : ```shell uv add "livekit-plugins-aws[realtime]" ``` ### 认证 AWS 插件需要 AWS 证书。在您设置下列环境变量 `.env` 文件 : ```shell AWS_ACCESS_KEY_ID=<your-aws-access-key-id> AWS_SECRET_ACCESS_KEY=<your-aws-secret-access-key> ``` ### 使用量 在一个内使用 Nova Sonic API `AgentSession`。例如,可以在 [语音 AI 快速启动](https://docs.livekit.io/agents/start/voice-ai.md). ```python from livekit.plugins import aws # Nova Sonic 2.0 (default) - supports text input and 16 voices session = AgentSession( llm=aws.realtime.RealtimeModel(), ) # Nova Sonic 2.5 - supports text input and the same voices as Nova Sonic 2.0 session = AgentSession( llm=aws.realtime.RealtimeModel.with_nova_sonic_2_5( voice="tiffany", turn_detection="MEDIUM" ), ) # Or explicitly specify Nova Sonic 2.0 session = AgentSession( llm=aws.realtime.RealtimeModel.with_nova_sonic_2( voice="tiffany", turn_detection="MEDIUM" ), ) # Nova Sonic 1.0 - audio-only, 11 voices session = AgentSession( llm=aws.realtime.RealtimeModel.with_nova_sonic_1( voice="matthew" ), ) ``` ### 参数 本节介绍一些现有参数。关于所有可用参数的完整参考,请参见: [插件引用](https://docs.livekit.io/reference/python/livekit/plugins/aws/experimental/realtime/realtime_model.html.md#livekit.plugins.aws.experimental.realtime.realtime_model.RealtimeModel). - **`model`** _(字符串)_(可选) - 默认 : `"amazon.nova-2-sonic-v1:0"`: Bedrock 型号 ID 用于实时推论. `"amazon.nova-2-5-sonic"` 用于新索尼奇 2.5 或 `"amazon.nova-sonic-v1:0"` 为Nova Sonic 1.0提供. - **`modalities`** _(字符串)_(可选) - 默认 : `"mixed"`: 输入/输出模式。有效值为: - `"mixed"` 允许音频和文本输入(Nova Sonic 2.0和2.5 ). - `"audio"` 允许只使用音频(Nova Sonic 1.0 ). - **`voice`** _(字符串)_(可选) - 默认 : `"tiffany"`: Nova Sonic API 语音的名称. Nova Sonic 2.0 和 2.5 支持 16 语音跨越 8 语言. Nova Sonic 1.0 支持 11 语音. 关于完整列表,参见 [声音](https://docs.aws.amazon.com/nova/latest/userguide/available-voices.html). - **`turn_detection`** _(字符串)_(可选) - 默认 : `"MEDIUM"`: 转动的敏感度。有效值是 `"HIGH"`, `"MEDIUM"`,以及 `"LOW"`。学习更多,看 [转动检测敏感度](#turn-detection). - **`region`** _(字符串)_(可选) - 默认 : `"us-east-1"`: Bedrock 运行时端点的 AWS 区域。默认为 `"us-east-1"`. - **`generate_reply_timeout`** _(浮动)_(可选) - 默认 : `10.0`: 超时数( 秒) `generate_reply()` 。这是请求中止前的最长等待时间 。 ## 转动检测敏感度 Nova Sonic包括基于VAD的内置转弯检测,具有可配置的敏感性: - " HIGH " :快速响应,快速检测暂停,可能会打断发言速度较慢。 - " MEDIUM " :平衡转向,推荐用于大多数案件。 - " LOW " :病人在答复前等待更长的时间,最好有深思熟虑或犹豫不决的发言者。 创建模型时配置回合检测 : ```python session = AgentSession( llm=aws.realtime.RealtimeModel.with_nova_sonic_2( turn_detection="MEDIUM" ), ) ``` ## 文本输入与 Nova Sonic 2.0 和 2.5 Nova Sonic 2.0 和 2.5 支持文本输入通过 `generate_reply()` 方法,允许程序代理响应。这对于让代理先发言、提供指示或模拟用户输入很有用。 `modalities="mixed"` 以启用文本输入。 ### 参数 - **`instructions`** _(字符串)_(可选) : 给代理用于回复的指令。 这是作为系统提示发送的, 以引导模型的回复 。 - **`user_input`** _(字符串)_(可选) : 需要响应的用户输入。 这是作为用户消息发送给模型, 并添加到Nova的对话上下文中 。 ### 实例 加入时让代理问候用户: ```python class Assistant(Agent): async def on_enter(self): await self.session.generate_reply( instructions="Greet the user warmly and introduce your capabilities" ) ``` 向代理发送指令以生成响应 : ```python await session.generate_reply( instructions="Greet the user and ask how you can help" ) ``` 发送用户输入给代理以生成响应 : ```python await session.generate_reply( user_input="Hello, I need help with my account" ) ``` ### 超时配置 配置超时 `generate_reply()` 电话: ```python session = AgentSession( llm=aws.realtime.RealtimeModel.with_nova_sonic_2( generate_reply_timeout=15.0 # seconds ), ) ``` ## 函数调用 用于 [函数工具](https://docs.livekit.io/agents/build/tools.md) 与 Nova Sonic 一起定义工具 `@function_tool` 装潢师和注册他们到你的 `Agent`Nova Sonic在谈话中援引这些内容,并将结果纳入其口头答复中。 工具结果以 JSON 格式发回 Nova Sonic, 因此返回字符串或 JSON 可串值, 如 a `dict`: ```python from livekit.agents import ToolError, function_tool @function_tool async def get_weather(city: str, units: str = "fahrenheit") -> dict[str, str | int] | ToolError: """Retrieve the current weather for a city. Args: city: The city to get the weather for. units: Temperature units, either 'celsius' or 'fahrenheit'. """ try: weather = await fetch_weather(city, units) except Exception as e: # After receiving this error, Nova Sonic will inform the user that the request wasn't successful and to try again return ToolError(f"Could not get weather for {city}: {e}") return {"city": city, "temperature": weather.temperature, "units": units} ``` 当工具返回( 或升起) a `ToolError`,将信息传递给Nova Sonic作为 `{"error": "<message>"}`让模特儿能优雅地恢复过来 ## 追加资源 以下资源提供更多信息,介绍Nova Sonic与LiveKit Agents的使用情况. - **[Python 软件包](https://pypi.org/project/livekit-plugins-aws/)**编号: `livekit-plugins-aws` 在 PyPI 上的软件包。 - **[插件引用](https://docs.livekit.io/reference/python/livekit/plugins/aws/experimental/realtime/index.html.md)**: Nova Sonic集成的参考文献. - **[GitHub 重传](https://github.com/livekit/agents/tree/main/livekit-plugins/livekit-plugins-aws/livekit/plugins/aws/)**:查看来源或为LiveKit AWS插件做出贡献. - **[Nova 音效文件](https://docs.aws.amazon.com/nova/latest/userguide/speech.html)**: Nova Sonic API文档. - **[语音 AI 快速启动](https://docs.livekit.io/agents/start/voice-ai.md)**:开始使用LiveKit Agents和亚马逊Nova Sonic. - **[AWS AI 生态系统指南](https://docs.livekit.io/agents/integrations/aws.md)**: AWS AI和LiveKit代理集成的全过程概述. --- 这份文件是在2026 - 12-01T16:18:33.422Z. 本文件的最新版本见: [https://docs.livekit.io/agents/models/realtime/nova-sonic.md](https://docs.livekit.io/agents/models/realtime/nova-sonic.md). 要探索所有 LiveKit 文档,请参见 [页:1](https://docs.livekit.io/llms.txt).
查看原始来源