Model Studio Paraformer file transcription API

Updated at:

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.

Important

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.

Note

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

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

model

str

None

Required. The transcription model name. See Model overview.

file_urls

list[str]

None

Required. A list of HTTP/HTTPS URLs for audio or video files, with up to 100 entries.

channel_id

list[int]

[0]

Optional. Indexes of audio tracks to recognize, starting from 0. For example, [0] recognizes the first track and [0, 1] recognizes the first and second tracks separately.

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

task

str

None

Required. The output.task_id returned by async_call().

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

task

str

None

Required. The output.task_id returned by async_call().

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

status_code

int

The HTTP status code.

request_id

str

The request ID, used for troubleshooting.

code

str/null

The error code when the request fails.

message

str

The error message when the request fails.

output.task_id

str

The task ID.

output.task_status

str

The task status: PENDING (queued), RUNNING (processing), SUCCEEDED (succeeded), or FAILED (failed). Check subtask_status for each file's result.

output.results

list[object]

Transcription result information for each file.

output.results[].file_url

str

The file URL processed by the subtask.

output.results[].subtask_status

str

The subtask status of the file.

output.results[].transcription_url

str

The URL to download the result JSON after successful transcription.

output.results[].code

str

The error code when the subtask fails.

output.results[].message

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

file_url

str

The source audio or video file URL.

properties.audio_format

str

The audio format in the source file.

properties.channels

list[int]

Audio track indexes in the source file. For example, [0] for a single-track file and [0, 1] for a two-track file.

properties.original_sampling_rate

int

The source audio sample rate, in Hz.

properties.original_duration_in_milliseconds

int

The source audio duration, in milliseconds.

transcripts

list[object]

Transcription results for each audio track.

transcripts[].channel_id

int

The index of the audio track.

transcripts[].content_duration_in_milliseconds

int

The duration of speech in the track, in milliseconds.

transcripts[].text

str

The full transcript of the audio track.

transcripts[].sentences

list[object]

Sentence-level transcription results.

transcripts[].sentences[].begin_time

int

The sentence start time, in milliseconds.

transcripts[].sentences[].end_time

int

The sentence end time, in milliseconds.

transcripts[].sentences[].text

str

The sentence text.

transcripts[].sentences[].words

list[object]

Word-level transcription results.

transcripts[].sentences[].words[].begin_time

int

The word start time, in milliseconds.

transcripts[].sentences[].words[].end_time

int

The word end time, in milliseconds.

transcripts[].sentences[].words[].text

str

The word text.

transcripts[].sentences[].words[].punctuation

str

The punctuation after the word.

Important

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.