开发者指南 · 10
实时语音(S2S WebSocket)
10.1 S2S 模块(旧路径)
app/voice/router.py 提供 WebSocket 端点 /api/voice/ws,作为 OpenAI Realtime API 的代理。
text
浏览器 ──WebSocket──→ FastAPI ──WebSocket──→ wss://api.openai.com/v1/realtime- 工具注入:
session.update事件中包含 Admin 配置的工具集 - 鉴权:query 参数 JWT
- API Key:
S2S_API_KEY/S2S_BASE_URL
10.2 LiveKit 语音插件(推荐)
独立进程 plugins/voice/(LiveKit Agents)+ Core 路由 app/routes/voice_live.py:
text
浏览器 ─WebRTC→ LiveKit Server ← Worker(jellyfish_voice)
│
Worker ─HTTP/SSE─→ Core /api/voice/live/{session,delegate,llm/v1/chat/completions}
└── 委派复用 chat._stream_agent(yolo=True),thread_id 与文字对话共享- 桥接令牌:
app/voice/live_token.py(X-Bridge-Token/ Bearer 用于 LLM 网关) - 前台配置:
users/{uid}/voice_agent_config.json;调音台 设置 → 语音 - 部署:
docker-compose.voice.yml(livekit-server + voice-worker);LIVEKIT_*/VOICE_BRIDGE_SECRET/FISH_*/DASHSCOPE_API_KEY等由部署方配置