多说话人转写
将多说话人音频转为带说话人信息的转写结果,适合会议、访谈和播客。
Endpoint
POST
/v1/audio/transcriptions模型名称
moss-transcribe-diarize-pro创建 API Key
进入 API Key 管理平台,创建 API Key,并保存为环境变量。不要把 API Key 写进客户端代码或提交到仓库。
环境变量 MOSS_API_KEY=<your_api_key_here>准备请求输入
准备一个本地多说话人音频文件,通过
multipart/form-data将文件和转写参数一起提交;传入diarize=true启用说话人识别。字段类型要求说明当前填写
moss-transcribe-diarize-pro。通过
multipart/form-data上传的本地音频文件。固定为
true,启用说话人识别。转写结果格式,可选
json、text,默认json。需要返回speaker和segments时使用json。请求体 model=moss-transcribe-diarize-pro file=@./audio.mp3 diarize=true response_format=json发起第一次请求
多说话人转写
请求示例 curl -X POST "https://api.mosi.cn/v1/audio/transcriptions" \ -H "Authorization: Bearer $MOSS_API_KEY" \ -F "model=moss-transcribe-diarize-pro" \ -F "file=@./audio.mp3" \ -F "diarize=true" \ -F "response_format=json"流式输出
在同一个 multipart 请求中增加
stream=true,即可通过 SSE 持续读取转写事件。流式请求不能同时传async=true。curl -N -X POST "https://api.mosi.cn/v1/audio/transcriptions" \ -H "Authorization: Bearer $MOSS_API_KEY" \ -H "Accept: text/event-stream" \ -F "model=moss-transcribe-diarize-pro" \ -F "file=@./audio.mp3" \ -F "diarize=true" \ -F "stream=true" \ -F "response_format=verbose_json"获取任务结果
同步调用时,从响应中读取
text、segments等结果;使用 SSE 时读取至transcript.text.done。传入async=true时会返回task_id,可通过GET /v1/audio/tasks/{task_id}查询任务结果。查询转写任务 curl https://api.mosi.cn/v1/audio/tasks/$TASK_ID \ -H "Authorization: Bearer $MOSS_API_KEY"验证成功
成功标志:拿到带说话人信息的转写结果。成功响应可包含
segments,每个 segment 含start、end、text、speaker。