wss://openapi.myvocal.ai/asr/realtime?api-key=YOUR_API_KEY&model_id=echo_v1_realtime&audio_format=pcm_16000&commit_mode=manualapi-key 与 model_id 必填。通过 commit_mode 选择提交方式,完整连接参数见下方“请求参数”。echo_v1_realtime。医疗模型 echo_v2_medical 不支持此接口,使用时握手返回 HTTP 400;医疗录音请使用文件转录。session_started 后,以 JSON 文本消息发送音频。以下字段属于消息体,不属于连接 URL:| 字段 | 类型 | 说明 |
|---|---|---|
message_type | string | 固定为 input_audio_chunk |
audio_base_64 | string | PCM 音频数据的 Base64,不包含 WAV 文件头 |
sample_rate | integer | 与连接的音频格式一致,例如 16000 |
commit | boolean | 手动模式需要提交时设为 true |
previous_text | string,可选 | 仅会话第一帧音频允许传入的上下文文本 |
BASE64_PCM_BYTES 需替换为真实音频数据):{
"message_type": "input_audio_chunk",
"audio_base_64": "BASE64_PCM_BYTES",
"sample_rate": 16000,
"commit": false
}previous_text 添加到第一帧消息。后续音频帧不要重复携带该字段;也不要把它放入 URL Query。commit_mode=manualcommit=false 的音频帧,在一个片段的最后一帧设置 commit=true,随后等待最终结果。commit_mode=vadmessage_type 分发事件。事件类型与示例如下。| 事件 | 用途 |
|---|---|
session_started | 会话已建立,可以发送音频 |
partial_transcript | 中间结果,文本可能继续变化 |
committed_transcript | 当前片段的最终文本 |
committed_transcript_with_timestamps | 带逐词信息的最终结果 |
{"message_type":"partial_transcript","text":"Hello"}{"message_type":"committed_transcript","text":"Hello world."}word_timestamps=true 后,处理 committed_transcript_with_timestamps 中的 words。开启 include_language_detection=true 时,关注带时间戳的最终事件中返回的语言信息;同一片段可能先收到普通最终事件,再收到增强事件,不要重复保存两份文本。error、auth_error、quota_exceeded_error、input_error、invalid_request 等错误事件。例如后续音频帧重复传 previous_text 会触发输入错误。audio_format 匹配。建议以小片段持续发送,同时持续接收事件。连接 URL 中包含 Key,不要完整记录到日志。