Model Studio Paraformer file transcription API
The Model Studio Paraformer file transcription API converts speech in audio or video files into text, with full transcripts, sentences, words, and timestamps. This topic describes task submission, query methods, and transcription results in the DashScope Python SDK.
Overview
File transcription is asynchronous. Submit file URLs to obtain a task ID, then wait for or query the task to retrieve each file's transcription. The model performs punctuation prediction and inverse text normalization by default.
This API uses a DashScope API key from Alibaba Cloud Model Studio. The API key and the project Appkey and token used by Intelligent Speech Interaction belong to different authentication systems.
For technical assistance, submit a ticket.
Model overview
Use model to specify the transcription model. The example uses paraformer-v2. For supported languages, sample rates, and use cases, see Non-real-time speech recognition.
Prerequisites
Activate Model Studio, obtain an API key for the workspace, and configure it in the
DASHSCOPE_API_KEYenvironment variable. For instructions, see Obtain and configure an API key.Install the DashScope Python SDK. For instructions, see Install the DashScope SDK.
The example uses DashScope Python SDK 1.27.7. Set the DASHSCOPE_WORKSPACE_ID environment variable to the workspace ID to construct the workspace-specific domain for China (Beijing).
Limits
Provide files through HTTP or HTTPS URLs that the service can download. A request supports up to 100 file URLs. Each file must not exceed 2 GB.
Supported audio and video file formats include
.aac,.amr,.avi,.flac,.flv,.m4a,.mkv,.mov,.mp3,.mp4,.mpeg,.ogg,.opus,.wav,.webm,.wma, and.wmv. A format can have multiple encoding variants, not all of which can be recognized.Transcription results and download URLs are valid for 24 hours after the task completes. Retrieve and save results within this period.
The service processes file transcription tasks on a best-effort basis. Queue time depends on the queue length and the duration of files in other tasks. An exact waiting time cannot be provided, but tasks usually leave the queue within a few minutes. Once processing starts, speech recognition runs at several hundred times real-time speed.
To reduce file size, preprocess the file before submitting the transcription task.
Code example
The following Python example transcribes two audio files containing Chinese and English speech, waits for completion, and reads each result JSON. Replace file_urls with the URLs of other files as needed.
import json
import os
from http import HTTPStatus
from urllib.request import urlopen
import dashscope
from dashscope.audio.asr import Transcription
dashscope.api_key = os.environ["DASHSCOPE_API_KEY"]
workspace_id = os.environ["DASHSCOPE_WORKSPACE_ID"]
dashscope.base_http_api_url = (
f"https://{workspace_id}.cn-beijing.maas.aliyuncs.com/api/v1"
)
response = Transcription.async_call(
model="paraformer-v2",
file_urls=[
"https://dashscope.oss-cn-beijing.aliyuncs.com/samples/audio/paraformer/hello_world_female.wav",
"https://dashscope.oss-cn-beijing.aliyuncs.com/samples/audio/paraformer/hello_world_male.wav",
],
)
if response.status_code != HTTPStatus.OK:
raise RuntimeError(f"{response.code}: {response.message}")
response = Transcription.wait(task=response.output.task_id)
if response.status_code != HTTPStatus.OK:
raise RuntimeError(f"{response.code}: {response.message}")
for result in response.output.get("results", []):
if result["subtask_status"] == "SUCCEEDED":
with urlopen(result["transcription_url"]) as audio_result:
transcription = json.load(audio_result)
print(json.dumps(transcription, ensure_ascii=False, indent=2))
else:
print(result["file_url"], result.get("code"), result.get("message"))
API reference
The core class is dashscope.audio.asr.Transcription. After submitting a task, use wait() to block until completion or fetch() to query the current status.
async_call()
Transcription.async_call() asynchronously submits a file transcription task and returns a task ID.
Request parameters
|
Parameter |
Type |
Default |
Description |
|
|
str |
None |
Required. The transcription model name. See Model overview. |
|
|
list[str] |
None |
Required. A list of HTTP/HTTPS URLs for audio or video files, with up to 100 entries. |
|
|
list[int] |
|
Optional. Indexes of audio tracks to recognize, starting from 0. For example, |
Response example
{
"status_code": 200,
"request_id": "<request_id>",
"code": "",
"message": "",
"output": {
"task_id": "<task_id>",
"task_status": "PENDING"
},
"usage": null
}
output.task_id uniquely identifies the task for subsequent wait or query calls. For common response fields, see Response fields.
wait()
Transcription.wait() blocks until the task ends. It continues waiting while the task is PENDING or RUNNING, and returns the result when the task reaches SUCCEEDED or FAILED.
Request parameters
|
Parameter |
Type |
Default |
Description |
|
|
str |
None |
Required. The |
For the response structure of a completed task, see Completed task example.
fetch()
Transcription.fetch() queries the task status once and returns without waiting for completion. To poll the task, continue querying while its status is PENDING or RUNNING, then process the result when it reaches SUCCEEDED or FAILED.
Request parameters
|
Parameter |
Type |
Default |
Description |
|
|
str |
None |
Required. The |
The following example shows the main response fields while the task is RUNNING.
{
"status_code": 200,
"request_id": "<request_id>",
"code": null,
"message": "",
"output": {
"task_id": "<task_id>",
"task_status": "RUNNING"
},
"usage": null
}
For the response structure of a completed task, see Completed task example.
Response fields
All three methods return an SDK response object. After the task completes, output.results in the response from wait() or fetch() contains each file's subtask result.
|
Field path |
Type |
Description |
|
|
int |
The HTTP status code. |
|
|
str |
The request ID, used for troubleshooting. |
|
|
str/null |
The error code when the request fails. |
|
|
str |
The error message when the request fails. |
|
|
str |
The task ID. |
|
|
str |
The task status: |
|
|
list[object] |
Transcription result information for each file. |
|
|
str |
The file URL processed by the subtask. |
|
|
str |
The subtask status of the file. |
|
|
str |
The URL to download the result JSON after successful transcription. |
|
|
str |
The error code when the subtask fails. |
|
|
str |
The error message when the subtask fails. |
Completed task example
The following example shows the main response fields after one file is successfully transcribed. <task_id>, <request_id>, and <transcription_url> are placeholders. Read the actual values from the response.
{
"status_code": 200,
"request_id": "<request_id>",
"code": null,
"message": "",
"output": {
"task_id": "<task_id>",
"task_status": "SUCCEEDED",
"results": [
{
"file_url": "https://dashscope.oss-cn-beijing.aliyuncs.com/samples/audio/paraformer/hello_world_female.wav",
"transcription_url": "<transcription_url>",
"subtask_status": "SUCCEEDED"
}
]
},
"usage": {"duration": 4}
}
Transcription results
Each successfully transcribed file has a result JSON available through transcription_url. The following excerpt is from the female-voice sample, with only the first two words retained in words. The audio contains Chinese and English speech, so the transcript retains both languages.
{
"file_url": "https://dashscope.oss-cn-beijing.aliyuncs.com/samples/audio/paraformer/hello_world_female.wav",
"properties": {
"audio_format": "pcm_s16le",
"channels": [0],
"original_sampling_rate": 16000,
"original_duration_in_milliseconds": 4087
},
"transcripts": [
{
"channel_id": 0,
"content_duration_in_milliseconds": 4080,
"text": "Hello world, 来自阿里巴巴达摩院语音实验室。",
"sentences": [
{
"begin_time": 0,
"end_time": 4080,
"text": "Hello world, 来自阿里巴巴达摩院语音实验室。",
"sentence_id": 1,
"words": [
{"begin_time": 0, "end_time": 480, "text": "Hello ", "punctuation": ""},
{"begin_time": 480, "end_time": 720, "text": "world", "punctuation": ", "}
]
}
]
}
]
}
|
Field path |
Type |
Description |
|
|
str |
The source audio or video file URL. |
|
|
str |
The audio format in the source file. |
|
|
list[int] |
Audio track indexes in the source file. For example, |
|
|
int |
The source audio sample rate, in Hz. |
|
|
int |
The source audio duration, in milliseconds. |
|
|
list[object] |
Transcription results for each audio track. |
|
|
int |
The index of the audio track. |
|
|
int |
The duration of speech in the track, in milliseconds. |
|
|
str |
The full transcript of the audio track. |
|
|
list[object] |
Sentence-level transcription results. |
|
|
int |
The sentence start time, in milliseconds. |
|
|
int |
The sentence end time, in milliseconds. |
|
|
str |
The sentence text. |
|
|
list[object] |
Word-level transcription results. |
|
|
int |
The word start time, in milliseconds. |
|
|
int |
The word end time, in milliseconds. |
|
|
str |
The word text. |
|
|
str |
The punctuation after the word. |
Paraformer transcribes only the parts of an audio track that the model identifies as speech, and meters and bills by their duration. Non-speech segments are neither metered nor billed. The duration of speech is usually shorter than the original audio duration. The model's speech detection may differ from the actual speech content.
Error handling
For a failed request, check the response's status_code, code, and message. For a failed file subtask, check code and message in output.results[]. For error codes and solutions, see Model Studio error codes.