用途:在 Python 项目中通过 Deepgram SDK 调用会话式 STT / Flux(/v2/listen),实现对话轮次感知的流式转录。适合需要明确轮次边界、面向人与人/人与智能体对话、并希望比 v1 utterance_end 更低延迟轮次信号的会话式界面。一般转录(字幕、批量、非会话)应改用 deepgram-python-speech-to-text;完整交互智能体用 deepgram-python-voice-agent;分析用 deepgram-python-audio-intelligence。
能力与关键参数:use client.listen.v2.connect(model="flux-general-en", ...),模型必须为 Flux(flux-general-en 或 flux-general-multi)。可用编码 linear16、mulaw 等,sample_rate 为字符串如 "16000",容器化音频可省略。eager_eot_threshold、eot_threshold、eot_timeout_ms 控制回合结束;keyterm 做领域词偏置;mip_opt_out、tag 为元数据/隐私标志;language_hint 仅用于 flux-general-multi。v2 无 language 参数。应用可控轮次时设 eot_threshold="1.0" 并配较大 eot_timeout_ms,再用 conn.send_force_end_turn()(需部署启用)。
用法与事件:注册 EventType.OPEN/MESSAGE/CLOSE/ERROR;服务端事件含 ListenV2Connected、ListenV2ConfigureSuccess/Failure、ListenV2TurnInfo(回合转录与事件)、ListenV2FatalError;客户端消息含 ListenV2Media/Configure/ForceEndTurn/CloseStream。异步可用 AsyncDeepgramClient,await conn.start_listening()。建议音频分块约 80ms。
限制与注意:认证头为 Authorization: Token <api_key>,仅 WSS 无 REST。用 /v2/listen 而非 /v1/listen;非 Flux 模型会被拒绝;关闭用 send_close_stream(ListenV2CloseStream(type="CloseStream")),不是 v1 的 send_finalize;消息可能为类型对象或原始 dict,需同时处理;socket_client.py 已手动修补并冻结,重新生成时不要覆盖。