语音转写(异步)

平台提供异步语音转写 API,适用于长音频的语音转写,单个音频文件长度小于 5 小时。

  1. 支持说话人分离,可区分不同说话人段落。
  2. 支持智能断句与标点预测,提升文本可读性。
  3. 支持时间戳信息返回,可直接用于字幕、检索、音视频对齐。
  4. 支持上下文与热词增强,提升专有名词、行业术语识别率。

支持语言

1 中文(Chinese)2 英语(English)3 阿拉伯语(Arabic)
4 德语(German)5 西班牙语(Spanish)6 法语(French)
7 印尼语(Indonesian)8 日语(Japanese)9 韩语(Korean)
10 葡萄牙语(Portuguese)11 俄语(Russian)12 土耳其语(Turkish)
13 越南语(Vietnamese)14 泰语(Thai)15 意大利语(Italian)
16 粤语(Cantonese)17 长沙话(Changsha dialect)18 客家话(Hakka dialect)
19 闽南话(Hokkien)20 南昌话(Nanchang dialect)21 山西话(Shanxi dialect)
22 苏州话(Suzhou dialect)23 上海话(Shanghainese)24 济南话(Jinan dialect)
25 四川话(Sichuanese)26 武汉话(Wuhan dialect)

使用流程

  1. 先调用 文件上传 API 上传音频文件并获取 file_id
  2. 调用 创建异步语音转写任务 API,获取 task_id
  3. 调用 查询语音转写任务状态 API,基于 task_id 获取语音转写任务进度
  4. 当任务完成时,会返回转写结果

过程示例

1. 获取 file_id

Python
"""
本示例用于获取待转写音频的 file_id。注意:需要先将密钥信息写入环境变量 `API_KEY`。
"""
import requests
import os

api_key = os.environ.get("API_KEY")
url = "https://maas-api.unisound.com/v1/files/upload"

payload = {'purpose': 'a2t_async_input'}
files=[
  ('file',('test.mp3',open('path/to/test.mp3','rb'),'audio/mpeg'))
]
headers = {
  'authority': 'maas-api.unisound.com',
  'Authorization': f'Bearer {api_key}'
}

response = requests.request("POST", url, headers=headers, data=payload, files=files)

print(response.text)

2. 创建语音转写任务

Python
"""
本示例用于创建语音转写任务。注意:需要先将密钥信息写入环境变量 `API_KEY`。
"""
import requests
import json
import os

api_key = os.environ.get("API_KEY")
url = "https://maas-api.unisound.com/v1/audio/asr/tasks"

payload = json.dumps({
  "model": "u2-asr",
  "file_id": <file_id>,
  "format": "mp3"
})
headers = {
  'Authorization': f'Bearer {api_key}',
  'Content-Type': 'application/json'
}

response = requests.request("POST", url, headers=headers, data=payload)

print(response.text)

3. 查询语音转写进度

Python
"""
本示例用于查询语音转写进度。注意:需要先将密钥信息写入环境变量 `API_KEY`,并将需要查询任务的 id 写入环境变量 `TASK_ID`。
"""
import requests
import json
import os

task_id = os.environ.get("TASK_ID")
api_key = os.environ.get("API_KEY")
url = f"https://maas-api.unisound.com/v1/audio/asr/tasks/{task_id}"

payload = {}
headers = {
  'Authorization': f'Bearer {api_key}',
  'content-type': 'application/json',
}

response = requests.request("GET", url, headers=headers, data=payload)

print(response.text)