|
| 1 | +# NaviGo AI - 实时语音助手 Agent |
| 2 | + |
| 3 | +基于火山引擎 VeADK 和 AgentKit 构建的入门级实时语音助手 Agent,展示如何创建一个具备旅行规划能力的 AI Agent。 |
| 4 | + |
| 5 | +## 概述 |
| 6 | + |
| 7 | +本示例是 AgentKit 与豆包端到端实时语音大模型结合的例子。 |
| 8 | + |
| 9 | +## 核心功能 |
| 10 | + |
| 11 | +- 创建一个简单的实时语音助手 Agent 实时语音聊天需要同时处理多个任务:听、想、说 |
| 12 | +- 豆包端到端实时语音大模型API即RealtimeAPI支持低延迟、多模式交互,可用于构建语音到语音的对话工具 |
| 13 | + |
| 14 | +## Agent 能力 |
| 15 | + |
| 16 | +```text |
| 17 | +用户消息 |
| 18 | + ↓ |
| 19 | +AgentKit 运行时 |
| 20 | + ↓ |
| 21 | +NaviGo AI Agent |
| 22 | + ├── VeADK Agent (对话引擎) |
| 23 | + └── 端到端实时语音大模型 (LLM) |
| 24 | +``` |
| 25 | + |
| 26 | +### 核心组件 |
| 27 | + |
| 28 | +| 组件 | 描述 | |
| 29 | +| - | - | |
| 30 | +| **Agent 服务** | [agent.py](https://github.com/volcengine/agentkit-samples/blob/main/02-use-cases/beginner/realtime_voice/agent.py) - 主应用程序,定义 Agent 处理音频和文本转录 | |
| 31 | +| **测试客户端** | [interface.html](https://github.com/volcengine/agentkit-samples/blob/main/02-use-cases/beginner/realtime_voice/client/interface.html) - 基于 HTML5 实现的实时语音助手界面 | |
| 32 | +| **项目配置** | [pyproject.toml](https://github.com/volcengine/agentkit-samples/blob/main/02-use-cases/beginner/realtime_voice/pyproject.toml) - 依赖管理(uv 工具) | |
| 33 | +| **AgentKit 配置** | agentkit.yaml - 云端部署配置文件 | |
| 34 | + |
| 35 | +### 代码特点 |
| 36 | + |
| 37 | +**Agent 定义**([agent.py](https://github.com/volcengine/agentkit-samples/blob/main/02-use-cases/beginner/realtime_voice/agent.py#L43-L48)): |
| 38 | + |
| 39 | +```python |
| 40 | + |
| 41 | +agent = Agent( |
| 42 | + name="voice_assistant_agent", |
| 43 | + model=MODEL, |
| 44 | + instruction=SYSTEM_INSTRUCTION, |
| 45 | + |
| 46 | +) |
| 47 | + |
| 48 | +``` |
| 49 | + |
| 50 | +**语音配置**([agent.py](https://github.com/volcengine/agentkit-samples/blob/main/02-use-cases/beginner/realtime_voice/agent.py#L78-L90)): |
| 51 | + |
| 52 | +```python |
| 53 | +# Create run config with audio settings |
| 54 | +run_config = RunConfig( |
| 55 | + streaming_mode=StreamingMode.BIDI, |
| 56 | + speech_config=types.SpeechConfig( |
| 57 | + voice_config=types.VoiceConfig( |
| 58 | + prebuilt_voice_config=types.PrebuiltVoiceConfig( |
| 59 | + voice_name=VOICE_NAME |
| 60 | + ) |
| 61 | + ) |
| 62 | + ), |
| 63 | + response_modalities=["AUDIO"], |
| 64 | + output_audio_transcription=types.AudioTranscriptionConfig(), |
| 65 | + input_audio_transcription=types.AudioTranscriptionConfig(), |
| 66 | +) |
| 67 | +``` |
| 68 | + |
| 69 | +## 目录结构说明 |
| 70 | + |
| 71 | +```bash |
| 72 | +realtime_voice/ |
| 73 | +├── agent.py # Agent 应用入口 |
| 74 | +├── core_utils.py # 核心工具函数(如音频处理) |
| 75 | +├── client/ # 测试客户端目录 |
| 76 | +│ ├── interface.html # 实时语音助手界面(HTML5 + WebSocket) |
| 77 | +├── requirements.txt # Python 依赖列表 (agentkit部署时需要指定依赖文件) |
| 78 | +├── pyproject.toml # 项目配置(uv 依赖管理) |
| 79 | +├── agentkit.yaml # AgentKit 部署配置(运行agentkit config之后会自动生成) |
| 80 | +├── Dockerfile # Docker 镜像构建文件(运行agentkit config之后会自动生成) |
| 81 | +└── README.md # 项目说明文档 |
| 82 | +``` |
| 83 | + |
| 84 | +## 本地运行 |
| 85 | + |
| 86 | +### 前置准备 |
| 87 | + |
| 88 | +**1. 开通豆包实时语音模型服务:** |
| 89 | + |
| 90 | +- 访问 [火山控制台](https://console.volcengine.com/speech/new/setting/activate?projectName=default) |
| 91 | +- 开通端到端实时语音模型服务 |
| 92 | + |
| 93 | +**2. 获取APP_ID 和 API_KEY:** |
| 94 | + |
| 95 | +- 参考 [控制台使用FAQ](https://www.volcengine.com/docs/6561/196768?lang=zh#q1%EF%BC%9A%E5%93%AA%E9%87%8C%E5%8F%AF%E4%BB%A5%E8%8E%B7%E5%8F%96%E5%88%B0%E4%BB%A5%E4%B8%8B%E5%8F%82%E6%95%B0appid%EF%BC%8Ccluster%EF%BC%8Ctoken%EF%BC%8Cauthorization-type%EF%BC%8Csecret-key-%EF%BC%9F) 获取 APP_ID 和 API_KEY |
| 96 | + |
| 97 | +**3. 获取火山引擎访问凭证:** |
| 98 | + |
| 99 | +- 参考 [用户指南](https://www.volcengine.com/docs/6291/65568?lang=zh) 获取 AK/SK |
| 100 | + |
| 101 | +### 依赖安装 |
| 102 | + |
| 103 | +#### 1. 安装 uv 包管理器 |
| 104 | + |
| 105 | +```bash |
| 106 | +# macOS / Linux(官方安装脚本) |
| 107 | +curl -LsSf https://astral.sh/uv/install.sh | sh |
| 108 | + |
| 109 | +# 或使用 Homebrew(macOS) |
| 110 | +brew install uv |
| 111 | +``` |
| 112 | + |
| 113 | +#### 2. 初始化项目依赖 |
| 114 | + |
| 115 | +```bash |
| 116 | +# 进入项目目录 |
| 117 | +cd 02-use-cases/beginner/realtime_voice |
| 118 | +``` |
| 119 | + |
| 120 | +使用 `uv` 工具来安装本项目依赖: |
| 121 | + |
| 122 | +```bash |
| 123 | +# 如果没有 `uv` 虚拟环境,可以使用命令先创建一个虚拟环境 |
| 124 | +uv venv --python 3.12 |
| 125 | + |
| 126 | +# 使用 `pyproject.toml` 管理依赖 |
| 127 | +uv sync |
| 128 | + |
| 129 | +# 激活虚拟环境 |
| 130 | +source .venv/bin/activate |
| 131 | +``` |
| 132 | + |
| 133 | +### 环境准备 |
| 134 | + |
| 135 | +```bash |
| 136 | +# 豆包端到端实时语音大模型名称 |
| 137 | +export MODEL=doubao_realtime_voice_model |
| 138 | +# 豆包端到端实时语音大模型APP_ID 和 API_KEY |
| 139 | +export MODEL_REALTIME_APP_ID=<Your APP_ID> |
| 140 | +export MODEL_REALTIME_API_KEY=<Your API_KEY> |
| 141 | + |
| 142 | +# 火山引擎访问凭证(必需) |
| 143 | +export VOLCENGINE_ACCESS_KEY=<Your Access Key> |
| 144 | +export VOLCENGINE_SECRET_KEY=<Your Secret Key> |
| 145 | + |
| 146 | +``` |
| 147 | + |
| 148 | +### 调试方法 |
| 149 | + |
| 150 | +#### 方式一:命令行测试 |
| 151 | + |
| 152 | +```bash |
| 153 | +cd realtime_voice |
| 154 | + |
| 155 | +# 启动 Agent 服务 |
| 156 | +uv run agent.py |
| 157 | +# 服务将监听 http://0.0.0.0:8000 |
| 158 | + |
| 159 | +# 新开客户端 |
| 160 | +# 在浏览器中打开 client/interface.html,客户端将自动连接到 WebSocket 服务器。 |
| 161 | +``` |
| 162 | + |
| 163 | +**运行效果**: |
| 164 | + |
| 165 | + |
| 166 | + |
| 167 | +## AgentKit 部署 |
| 168 | + |
| 169 | +### 前置准备 |
| 170 | + |
| 171 | +**重要提示**:在运行本示例之前,请先访问 [AgentKit 控制台授权页面](https://console.volcengine.com/agentkit/region:agentkit+cn-beijing/auth?projectName=default) 对所有依赖服务进行授权,确保案例能够正常执行。 |
| 172 | + |
| 173 | +**1. 开通豆包实时语音模型服务:** |
| 174 | + |
| 175 | +- 访问 [火山控制台](https://console.volcengine.com/speech/new/setting/activate?projectName=default) |
| 176 | +- 开通端到端实时语音模型服务 |
| 177 | + |
| 178 | +**2. 获取APP_ID 和 API_KEY:** |
| 179 | + |
| 180 | +- 参考 [控制台使用FAQ](https://www.volcengine.com/docs/6561/196768?lang=zh#q1%EF%BC%9A%E5%93%AA%E9%87%8C%E5%8F%AF%E4%BB%A5%E8%8E%B7%E5%8F%96%E5%88%B0%E4%BB%A5%E4%B8%8B%E5%8F%82%E6%95%B0appid%EF%BC%8Ccluster%EF%BC%8Ctoken%EF%BC%8Cauthorization-type%EF%BC%8Csecret-key-%EF%BC%9F) 获取 APP_ID 和 API_KEY |
| 181 | + |
| 182 | +**3. 获取火山引擎访问凭证:** |
| 183 | + |
| 184 | +- 参考 [用户指南](https://www.volcengine.com/docs/6291/65568?lang=zh) 获取 AK/SK |
| 185 | + |
| 186 | +### AgentKit 云上部署 |
| 187 | + |
| 188 | +```bash |
| 189 | +cd realtime_voice |
| 190 | + |
| 191 | +# 配置部署参数 |
| 192 | +agentkit config |
| 193 | + |
| 194 | +# 启动云端服务 |
| 195 | +agentkit launch |
| 196 | + |
| 197 | +# 测试部署的 Agent |
| 198 | +# 需要编辑 client/interface.html,将其中的第 168 行的 ws://localhost:8000 修改为 agentkit.yaml 中生成的 runtime_endpoint 字段 |
| 199 | +# 在浏览器中打开 client/interface.html,客户端将自动连接到 WebSocket 服务器。 |
| 200 | +``` |
| 201 | + |
| 202 | +## 示例提示词 |
| 203 | + |
| 204 | +## 效果展示 |
| 205 | + |
| 206 | +## 下一步 |
| 207 | + |
| 208 | +## 常见问题 |
| 209 | + |
| 210 | +无。 |
| 211 | + |
| 212 | +## 参考资料 |
| 213 | + |
| 214 | +- [VeADK 官方文档](https://volcengine.github.io/veadk-python/) |
| 215 | +- [AgentKit 开发指南](https://volcengine.github.io/agentkit-sdk-python/) |
| 216 | +- [豆包实时语音模型服务](https://www.volcengine.com/docs/6561/1594356) |
| 217 | + |
| 218 | +## 代码许可 |
| 219 | + |
| 220 | +本工程遵循 Apache 2.0 License |
0 commit comments