录音文件转写 Python SDK
使用指南: 教程、代码示例和模型详情请参见录音文件转写。
文件必须为公开 URL(HTTP/HTTPS,如
通过 Transcription 类的
默认情况下,系统敏感词列表中的词会被替换为星号(
字段说明:
各模型支持的语言代码:
关键参数:
关键参数:
结果为 JSON 文件。
关键参数:
通过
限制条件
文件必须为公开 URL(HTTP/HTTPS,如 https://your-domain.com/file.mp3)。不支持本地文件和 Base64 编码。
通过 file_urls 参数传入 URL,每次请求最多 100 个。
- 音频格式:
aac、amr、avi、flac、flv、m4a、mkv、mov、mp3、mp4、mpeg、ogg、opus、wav、webm、wma、wmv
并非所有格式变体都经过测试,请先测试文件以验证转写效果。
请求参数
通过 Transcription 类的 async_call 方法传入以下参数。
| 参数 | 类型 | 默认值 | 是否必选 | 说明 |
|---|---|---|---|---|
| model | str | - | 是 | 模型 ID。参见模型可用性。 |
| file_urls | list[str] | - | 是 | 音频/视频文件 URL(HTTP/HTTPS),每次请求最多 100 个。 |
| phrase_id | str | - | 否 | 本次任务的热词表 ID,默认不启用。参见自定义热词。 |
| channel_id | list[int] | [0] | 否 | 要识别的音轨索引(从 0 开始)。[0] = 第一条音轨,[0, 1] = 第一条和第二条。每条音轨单独计费。 |
| special_word_filter | str | - | 否 | 敏感词过滤配置。参见敏感词过滤。 |
| diarization_enabled | bool | False | 否 | 启用说话人分离(仅限单声道)。结果中包含 speaker_id。参见识别结果。 |
| speaker_count | int | - | 否 | 预期说话人数量(2-100)。仅在 diarization_enabled 为 true 时生效,默认自动检测。该参数仅作为算法引导,不保证精确匹配。 |
| language_hints | list[str] | ["zh", "en"] | 否 | 语言代码。不设置时自动检测。参见支持的语言。 |
| speech_noise_threshold | float | - | 否 | 语音噪声阈值。 |
敏感词过滤
默认情况下,系统敏感词列表中的词会被替换为星号(*)。
通过 special_word_filter,您可以:
- 替换为
*:匹配的词变为星号。 - 过滤掉:匹配的词被移除。
filter_with_signed(object,可选):要替换为*的词。- 示例:"Help me test this code" 变为 "Help me **** this code"
word_list:要替换的词列表。
filter_with_empty(object,可选):要移除的词。- 示例:"Is the game about to start?" 变为 "Is the game about to?"
word_list:要移除的词列表。
system_reserved_filter(boolean,可选,默认值:true):启用系统过滤。为 true 时,系统敏感词列表中的词会被替换为*。
支持的语言
各模型支持的语言代码:
- fun-asr, fun-asr-2025-11-07:
zh:中文en:英文ja:日语
- fun-asr-2025-08-25:
zh:中文en:英文
- fun-asr-mtl, fun-asr-mtl-2025-08-25:
zh:中文en:英文ja:日语ko:韩语vi:越南语id:印尼语th:泰语ms:马来语tl:菲律宾语ar:阿拉伯语hi:印地语bg:保加利亚语hr:克罗地亚语cs:捷克语da:丹麦语nl:荷兰语et:爱沙尼亚语fi:芬兰语el:希腊语hu:匈牙利语ga:爱尔兰语lv:拉脱维亚语lt:立陶宛语mt:马耳他语pl:波兰语pt:葡萄牙语ro:罗马尼亚语sk:斯洛伐克语sl:斯洛文尼亚语sv:瑞典语
响应结果
TranscriptionResponse
TranscriptionResponse 包含任务信息(task_id、task_status)和 output 中的结果。参见 TranscriptionOutput。
点击查看 TranscriptionResponse 结构示例
点击查看 TranscriptionResponse 结构示例
- PENDING 状态
- RUNNING 状态
- SUCCEEDED 状态
- FAILED 状态
| 参数 | 说明 |
|---|---|
| status_code | HTTP 状态码。 |
| code | 忽略顶层 code,请检查 output.results[].code 获取错误信息。 |
| message | 忽略顶层 message,请检查 output.results[].message 获取错误信息。 |
| task_id | 任务 ID。 |
| task_status | 任务状态:PENDING、RUNNING、SUCCEEDED、FAILED。只要有一个子任务成功,任务状态即为 SUCCEEDED。请通过 subtask_status 查看各子任务的结果。 |
| results | 子任务结果。 |
| subtask_status | 子任务状态:PENDING、RUNNING、SUCCEEDED、FAILED。 |
| file_url | 音频文件 URL。 |
| transcription_url | 结果 URL(JSON 文件),可通过 HTTP 下载或读取。参见识别结果。 |
TranscriptionOutput
TranscriptionOutput 是 TranscriptionResponse 的 output 属性。
点击查看 TranscriptionOutput 结构示例
点击查看 TranscriptionOutput 结构示例
- PENDING 状态
- RUNNING 状态
- SUCCEEDED 状态
- FAILED 状态
| 参数 | 说明 |
|---|---|
| code | 错误码。 |
| message | 错误信息。 |
| task_id | 任务 ID。 |
| task_status | 任务状态:PENDING、RUNNING、SUCCEEDED、FAILED。只要有一个子任务成功,任务状态即为 SUCCEEDED。请通过 subtask_status 查看各子任务的结果。 |
| results | 子任务结果。 |
| subtask_status | 子任务状态:PENDING、RUNNING、SUCCEEDED、FAILED。 |
| file_url | 音频文件 URL。 |
| transcription_url | 结果 URL(JSON 文件),可通过 HTTP 下载或读取。参见识别结果。 |
识别结果
结果为 JSON 文件。
点击查看识别结果示例
点击查看识别结果示例
speaker_id 仅在启用说话人分离时出现。| 参数 | 类型 | 说明 |
|---|---|---|
| audio_format | string | 音频格式。 |
| channels | array[integer] | 音轨索引。[0] = 单音轨,[0, 1] = 双音轨。 |
| original_sampling_rate | integer | 采样率(Hz)。 |
| original_duration_in_milliseconds | integer | 音频时长(毫秒)。 |
| channel_id | integer | 音轨索引(从 0 开始)。 |
| content_duration_in_milliseconds | integer | 语音时长(毫秒)。 仅语音部分会被转写和计费,非语音部分不计入。语音时长通常短于音频时长。 |
| transcripts | string | 段落级文本。 |
| sentences | array | 句子级结果。 |
| words | array | 词级结果。 |
| begin_time | integer | 开始时间(毫秒)。 |
| end_time | integer | 结束时间(毫秒)。 |
| text | string | 转写文本。 |
| speaker_id | integer | 说话人索引(从 0 开始),仅在启用说话人分离时出现。 |
| punctuation | string | 该词之后预测的标点符号。 |
Transcription 类
通过 from dashscope.audio.asr import Transcription 导入。
| 方法 | 签名 | 说明 |
|---|---|---|
| async_call | @classmethod def async_call(cls, model: str, file_urls: List[str], phrase_id: str = None, api_key: str = None, workspace: str = None, **kwargs) -> TranscriptionResponse | 提交识别任务。 |
| wait | @classmethod def wait(cls, task: Union[str, TranscriptionResponse], api_key: str = None, workspace: str = None, **kwargs) -> TranscriptionResponse | 阻塞等待直到完成(SUCCEEDED 或 FAILED)。返回 TranscriptionResponse。 |
| fetch | @classmethod def fetch(cls, task: Union[str, TranscriptionResponse], api_key: str = None, workspace: str = None, **kwargs) -> TranscriptionResponse | 查询任务状态。返回 TranscriptionResponse。 |

