开发者资源

文档中心

产品指南、接入说明与 API 参考

文档中心语音识别
语音识别

实时语音识别

SenseTime TokenPlan 当前模型与接入说明

实时语音识别

低延迟实时转写,适合字幕和会议。当前只支持基础转写。

连接地址

wss://token.sensetime.com/ws/v1/realtime/transcriptions?model=seed-asr-2.0

model 可以放在 query,也可以在 session.update 里指定。建议显式传 model=seed-asr-2.0。

授权

支持设置 Header 的客户端,连接时携带:

Authorization: Bearer <API_KEY>

浏览器等无法设置 Header 的场景,把 access_token 放在 query:

wss://token.sensetime.com/ws/v1/realtime/transcriptions?access_token=$TOKENPLAN_API_KEY&model=seed-asr-2.0

access_token 可能出现在网关日志中。生产接入建议使用 Header。

消息流程

客户端                                  服务端
  | ---------- 建立连接 -----------------> |
  | <--------- session.created ---------- |
  | ---------- session.update ----------> |
  | <--------- session.updated ---------- |
  | ---------- input_audio_buffer.append > |
  | <--------- transcription.delta ------ |
  | <--------- transcription.completed -- |
  | ---------- sense_asr.session.finish > |
  | <--------- close 1000 --------------- |

session.update 必须是第一帧。

客户端事件

session.update

{
  "type": "session.update",
  "session": {
    "audio": {
      "input": {
        "format": { "type": "pcm", "rate": 16000 },
        "transcription": { "model": "seed-asr-2.0" }
      }
    }
  }
}

服务端返回 session.updated。其中一条会带上实际模型,input_audio_format 为 pcm16,sample_rate 为 16000。

input_audio_buffer.append

{
  "type": "input_audio_buffer.append",
  "audio": "<base64 编码的 PCM 字节>"
}

PCM 为 16 kHz、mono、s16le。建议每 100 ms 一帧(3200 字节)发送。audio 是这段 PCM 的 Base64。

sense_asr.session.finish

收到 completed 后发送:

{ "type": "sense_asr.session.finish" }

服务端以关闭码 1000 正常关闭连接。

服务端事件

增量:

{
  "type": "conversation.item.input_audio_transcription.delta",
  "text": "API gateway ...",
  "delta": { "transcript": "..." }
}

完成:

{
  "type": "conversation.item.input_audio_transcription.completed",
  "transcript": "API gateway processes https requests with JSON payloads.",
  "usage": { "type": "duration", "seconds": 5.08 }
}

上游异常时:

{
  "type": "error",
  "error": {
    "type": "invalid_request_error",
    "code": "invalid_request",
    "message": "..."
  }
}

当前限制

以下参数即使传入也会被忽略:

  • languages
  • prompt
  • keywords
  • sentence_timestamps、word_timestamps
  • speaker_diarization
  • translation
  • smart_edit
  • turn_detection(服务端 VAD 设置会被清空,使用显式 sense_asr.session.finish)

翻译、说话人分离和时间戳不要依赖本接口。

相关指南