Qwen-Audio-ASR-Filetrans non-real-time speech recognition Python SDK

Updated at:

This topic describes the parameters and interfaces of the Qwen-Audio-ASR-Filetrans non-real-time speech recognition Python SDK.

For input requirements such as supported audio formats, file size limits, and duration limits, see Audio specifications.

Prerequisites

Quick start

The following examples use DashScope Python SDK 2.0. The Core resource (client.audio.asr) provides methods to submit, wait for, and query tasks in either of the following ways:

  • Submit the task asynchronously and wait synchronously: after submitting the task, block the current thread until the task finishes and return the recognition result.
  • Submit the task asynchronously and query the result asynchronously: after submitting the task, call the query interface to retrieve the result whenever you need it.

Submit asynchronously and wait synchronously

Submit a task and wait
  1. Call client.audio.asr.jobs.create to submit a task with the request parameters.

    Note

    • The file transcription service processes tasks submitted through the API on a best-effort basis. After you submit a task, it enters the queued (PENDING) state. The queuing time depends on the queue length and the file duration, so it cannot be stated precisely, but it is usually within a few minutes. Once processing starts, speech recognition completes at hundreds of times real-time speed.
    • After each task finishes, the recognition result and the download URL are valid for 24 hours. After they expire, you can no longer query the task or download the result through the URL returned in a previous query.
  2. Call client.audio.asr.jobs.wait(job=job) to wait synchronously for completion.

    While the task is PENDING or RUNNING, jobs.wait continues to wait. It returns a Job when the task succeeds.

    The methods return a Job. Read the result list from job.results; each transcription_url points to a downloadable transcription result.

import json
import os

import dashscope

# Replace {WorkspaceId} with the actual workspace ID for the region.
client = dashscope.Client(
    api_key=os.environ["DASHSCOPE_API_KEY"],
    workspace="{WorkspaceId}",
    region="cn-beijing",
)

job = client.audio.asr.jobs.create(
    model="qwen-audio-3.1-asr-flash-filetrans",
    file_urls=["{YOUR_AUDIO_URL}"],
)

job = client.audio.asr.jobs.wait(job=job)

print(json.dumps(job.model_dump(), indent=4, ensure_ascii=False))

Submit asynchronously and query the result asynchronously

Submit a task and poll
  1. Call client.audio.asr.jobs.create to submit a task with the request parameters.

    Note

    • The file transcription service processes tasks submitted through the API on a best-effort basis. After you submit a task, it enters the queued (PENDING) state. The queuing time depends on the queue length and the file duration, so it cannot be stated precisely, but it is usually within a few minutes. Once processing starts, speech recognition completes at hundreds of times real-time speed.
    • After each task finishes, the recognition result and the download URL are valid for 24 hours. After they expire, you can no longer query the task or download the result through the URL returned in a previous query.
  2. Call client.audio.asr.jobs.fetch(task_id) in a loop and read the results when the task succeeds.

    Read the task status from job.status. This example queries the task once per second.

    The methods return a Job. Read the result list from job.results; each transcription_url points to a downloadable transcription result.

import json
import os
import time

import dashscope

# Replace {WorkspaceId} with the actual workspace ID for the region.
client = dashscope.Client(
    api_key=os.environ["DASHSCOPE_API_KEY"],
    workspace="{WorkspaceId}",
    region="cn-beijing",
)

job = client.audio.asr.jobs.create(
    model="qwen-audio-3.1-asr-flash-filetrans",
    file_urls=["{YOUR_AUDIO_URL}"],
)

while job.status in ("PENDING", "RUNNING"):
    time.sleep(1)
    job = client.audio.asr.jobs.fetch(task_id=job.task_id)

print(json.dumps(job.model_dump(), indent=4, ensure_ascii=False))

Service endpoints

The SDK defaults to the Beijing region. When creating dashscope.Client, set region to the target region and workspace to the workspace ID. The region setting applies only to this Client.

China (Beijing)

https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/api/v1

Replace {WorkspaceId} with your actual Workspace ID.

Singapore

https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1

Replace {WorkspaceId} with your actual Workspace ID.

API keys differ across regions. Use the API key for the corresponding region.

Request parameters

Set request parameters through client.audio.asr.transcribe or client.audio.asr.jobs.create.

ParameterTypeRequiredDescription

model

str

Yes

The model name.

file_urls

list[str]

Yes

A list of URLs of the audio or video files to transcribe. HTTP and HTTPS are supported. A single request supports only one URL. For input requirements such as supported audio formats, file size limits, and duration limits, see Audio specifications.

If the recording is stored in Alibaba Cloud OSS, the RESTful API supports temporary URLs prefixed with oss://, whereas the SDK does not support oss://-prefixed temporary URLs.

Important

  • A temporary URL is valid for 48 hours and cannot be used after it expires. Do not use it in production.

  • The upload credential interface is rate-limited to 100 QPS and cannot be scaled up. Do not use it in production, high-concurrency, or load-testing scenarios.

  • For production, use stable storage such as Alibaba Cloud OSS to keep files available long-term and avoid rate limiting.

  • If an audio file URL set to an OSS temporary public URL is unreachable, set X-DashScope-OssResourceResolve to enable in the request header (not recommended).

    The SDK does not support configuring request headers.

parameters.keep_dialect

bool

No

Supported by qwen-audio-3.1-asr-flash-filetrans only. Defaults to false, which transcribes dialects into standard Chinese. Set to true to preserve dialect expressions. Pass as a keyword argument with the same name. See API reference for details.

parameters.vocabulary_id

str

No

The ID of a precompiled hot word list.

Generate this ID in advance by calling the create hot word list API. Pass the ID during recognition to use the hot words in the list.

Suitable for scenarios where the vocabulary is known and relatively stable, and where you need to reuse the same word list across requests.

For usage details, see Precompiled hotwords.

parameters.vocabulary

dict

No

Instant hot words.

Passed as key-value pairs, where the key is the hot word text (string) and the value is the hot word weight (integer). No hot word list needs to be created in advance. The weight ranges from [1, 5] or is set to 50: a value in [1, 5] makes the model more likely to output the word as the value increases; a value of 50 designates a super hot word, which greatly improves recall, but the number of super hot words cannot exceed 50.

Suitable for temporary, session-level hot word optimization.

When instant and precompiled hotwords are configured together, the system merges both sets. If the merged set contains more than 2000 hotwords, the system randomly selects 2000 to use. For usage details, see Instant hotwords.

Example:

The following example reuses the client configured with the region and workspace in Quick start.

vocab = {"Zhang San": 5, "Li Si": 5}
result = client.audio.asr.jobs.create(
    model="qwen-audio-3.1-asr-flash-filetrans",
    file_urls=["{YOUR_AUDIO_URL}"],
    parameters={"vocabulary": vocab},
)

parameters.channel_id

list[int]

No

The index of the audio tracks to recognize in a multi-track audio file. The index starts at 0. For example, [0] recognizes the first track, and [0, 1] recognizes the first and second tracks at the same time. If you omit this parameter, only the first track is processed.

ImportantEach specified track is billed independently. For example, requesting [0, 1] for a single file incurs two separate charges.

Default value: [0].

parameters.special_word_filter

str

No

The sensitive words to process during speech recognition. You can set a different handling method for each sensitive word. For details, see Sensitive word filtering.

parameters.diarization_enabled

bool

No

Whether to enable speaker diarization. Disabled by default.

Applies only to mono audio. Multi-channel audio does not support speaker diarization.

When enabled, the recognition result includes a speaker_id field that distinguishes different speakers.

NoteWhen speaker diarization is enabled, keep the audio duration within 2 hours. Otherwise, recognition may fail or time out.

Default value: False.

For an example of speaker_id, see Recognition result description.

parameters.speaker_count

int

No

ImportantTakes effect only when speaker diarization is enabled (diarization_enabled is set to True).

A reference value for the number of speakers. The valid range is an integer from 2 to 100 (inclusive).

By default, the number of speakers is detected automatically. If you set this value, it only guides the algorithm to output the specified count when possible and does not guarantee that exact count.

No default value.

parameters.language_hints

list[str]

No

The language codes to recognize. If you can't determine the language in advance, leave it unset and the model detects the language automatically.

You can set up to 4 values. If you set more, only the first 4 take effect.

Click to view the supported language codes

  • zh: Chinese
  • en: English
  • ja: Japanese
  • ko: Korean
  • vi: Vietnamese
  • th: Thai
  • id: Indonesian
  • ms: Malay
  • tl: Filipino
  • hi: Hindi
  • ar: Arabic
  • fr: French
  • de: German
  • es: Spanish
  • pt: Portuguese
  • ru: Russian
  • it: Italian
  • nl: Dutch
  • sv: Swedish
  • da: Danish
  • fi: Finnish
  • no: Norwegian
  • el: Greek
  • pl: Polish
  • cs: Czech
  • hu: Hungarian
  • ro: Romanian
  • bg: Bulgarian
  • hr: Croatian
  • sk: Slovak

Response

Job

Job contains task information, raw output, and usage information.

{
    "task_id": "00000000-0000-0000-0000-000000000001",
    "status": "PENDING",
    "submitted_at": "2026-10-29 10:00:00.000",
    "scheduled_at": null,
    "finished_at": null,
    "output": {
        "task_id": "00000000-0000-0000-0000-000000000001",
        "task_status": "PENDING",
        "submit_time": "2026-10-29 10:00:00.000"
    },
    "usage": null
}
{
    "task_id": "00000000-0000-0000-0000-000000000001",
    "status": "RUNNING",
    "submitted_at": "2026-10-29 10:00:00.000",
    "scheduled_at": "2026-10-29 10:00:00.100",
    "finished_at": null,
    "output": {
        "task_id": "00000000-0000-0000-0000-000000000001",
        "task_status": "RUNNING",
        "submit_time": "2026-10-29 10:00:00.000",
        "scheduled_time": "2026-10-29 10:00:00.100"
    },
    "usage": null
}
{
    "task_id": "00000000-0000-0000-0000-000000000001",
    "status": "SUCCEEDED",
    "submitted_at": "2026-10-29 10:00:00.000",
    "scheduled_at": "2026-10-29 10:00:00.100",
    "finished_at": "2026-10-29 10:00:01.000",
    "output": {
        "task_id": "00000000-0000-0000-0000-000000000001",
        "task_status": "SUCCEEDED",
        "submit_time": "2026-10-29 10:00:00.000",
        "scheduled_time": "2026-10-29 10:00:00.100",
        "end_time": "2026-10-29 10:00:01.000",
        "results": [
            {
                "file_url": "{YOUR_AUDIO_URL}",
                "transcription_url": "{TRANSCRIPTION_URL}",
                "subtask_status": "SUCCEEDED"
            }
        ]
    },
    "usage": {
        "duration": 1,
        "total_tokens": 25,
        "output_tokens": 4,
        "input_tokens": 21
    }
}
{
    "task_id": "00000000-0000-0000-0000-000000000001",
    "status": "FAILED",
    "submitted_at": "2026-10-29 10:00:00.000",
    "scheduled_at": "2026-10-29 10:00:00.100",
    "finished_at": "2026-10-29 10:00:01.000",
    "output": {
        "task_id": "00000000-0000-0000-0000-000000000001",
        "task_status": "FAILED",
        "submit_time": "2026-10-29 10:00:00.000",
        "scheduled_time": "2026-10-29 10:00:00.100",
        "end_time": "2026-10-29 10:00:01.000",
        "code": "SERVER_ERROR",
        "file_url": "{YOUR_AUDIO_URL}",
        "subtask_status": "FAILED",
        "results": [
            {
                "file_url": "{YOUR_AUDIO_URL}",
                "subtask_status": "FAILED",
                "results": []
            }
        ]
    },
    "usage": null
}

Field

Description

task_id

The task ID.

status

The task status: PENDING, RUNNING, SUCCEEDED, or FAILED.

submitted_at

The submission time, corresponding to job.output["submit_time"].

scheduled_at

The processing start time, corresponding to job.output["scheduled_time"].

finished_at

The completion time, corresponding to job.output["end_time"].

output

The raw task output dictionary.

results

The subtask result list, accessible through job.results. Download the JSON file at transcription_url to retrieve the recognized text.

usage

Task usage information. qwen-audio-3.1-asr-flash-filetrans reports Token usage in input_tokens, output_tokens, and total_tokens. qwen-audio-3.0-asr-flash-filetrans is metered by duration.

Job.output

job.output is the raw task output dictionary returned by the service.

PENDING

{
    "task_id": "00000000-0000-0000-0000-000000000001",
    "task_status": "PENDING",
    "submit_time": "2026-10-29 10:00:00.000"
}

RUNNING

{
    "task_id": "00000000-0000-0000-0000-000000000001",
    "task_status": "RUNNING",
    "submit_time": "2026-10-29 10:00:00.000",
    "scheduled_time": "2026-10-29 10:00:00.100"
}

SUCCEEDED

{
    "task_id": "00000000-0000-0000-0000-000000000001",
    "task_status": "SUCCEEDED",
    "submit_time": "2026-10-29 10:00:00.000",
    "scheduled_time": "2026-10-29 10:00:00.100",
    "end_time": "2026-10-29 10:00:01.000",
    "results": [
        {
            "file_url": "{YOUR_AUDIO_URL}",
            "transcription_url": "{TRANSCRIPTION_URL}",
            "subtask_status": "SUCCEEDED"
        }
    ]
}

FAILED (raise_on_error=False)

{
    "task_id": "00000000-0000-0000-0000-000000000001",
    "task_status": "FAILED",
    "submit_time": "2026-10-29 10:00:00.000",
    "scheduled_time": "2026-10-29 10:00:00.100",
    "end_time": "2026-10-29 10:00:01.000",
    "code": "SERVER_ERROR",
    "file_url": "{YOUR_AUDIO_URL}",
    "subtask_status": "FAILED",
    "results": [
        {
            "file_url": "{YOUR_AUDIO_URL}",
            "subtask_status": "FAILED",
            "results": []
        }
    ]
}
ParameterDescription

code

The error code. Combine it with the message field and refer to Error codes to troubleshoot the issue.

message

The error message. Combine it with the code field and refer to Error codes to troubleshoot the issue.

task_id

Task ID.

task_status

Task status.

One of four states: PENDING, RUNNING, SUCCEEDED, and FAILED.

When a task contains multiple subtasks, the overall task status is marked as SUCCEEDED as long as any subtask succeeds. Check the subtask_status field to determine the result of each subtask.

results

Subtask recognition results.

subtask_status

Subtask status.

One of four states: PENDING, RUNNING, SUCCEEDED, and FAILED.

file_url

URL of the recognized audio.

transcription_url

URL of the audio recognition result.

The recognition result is saved as a JSON file. You can download the file from the link associated with transcription_url or read its content directly through an HTTP request. For the contents of the JSON file, see Recognition result description.

Recognition result description

The recognition result is saved as a JSON file.

{
    "file_url":"{YOUR_AUDIO_URL}",
    "properties":{
        "audio_format":"pcm_s16le",
        "channels":[
            0
        ],
        "original_sampling_rate":16000,
        "original_duration_in_milliseconds":3834
    },
    "transcripts":[
        {
            "channel_id":0,
            "content_duration_in_milliseconds":3720,
            "text":"Hello world, this is Alibaba Speech Lab.",
            "sentences":[
                {
                    "begin_time":100,
                    "end_time":3820,
                    "text":"Hello world, this is Alibaba Speech Lab.",
                    "sentence_id":1,
                    "speaker_id":0, //This field is displayed only when automatic speaker diarization is enabled
                    "words":[
                        {
                            "begin_time":100,
                            "end_time":596,
                            "text":"Hello ",
                            "punctuation":""
                        },
                        {
                            "begin_time":596,
                            "end_time":844,
                            "text":"world",
                            "punctuation":", "
                        }
                        // Other content is omitted here
                    ]
                }
            ]
        }
    ]
}

The following parameters are worth noting:

ParameterTypeDescription

audio_format

string

The audio format of the source file.

channels

array[integer]

The track index of the audio in the source file. For single-track audio, [0] is returned; for dual-track audio, [0, 1] is returned; and so on.

original_sampling_rate

integer

The sampling rate (Hz) of the audio in the source file.

original_duration_in_milliseconds

integer

The original audio duration (ms) in the source file.

channel_id

integer

The track index of the transcription result, starting from 0.

content_duration

integer

The duration (ms) of content in the track that is identified as speech.

NoteThe following billing description applies to qwen-audio-3.0-asr-flash-filetrans. qwen-audio-3.1-asr-flash-filetrans is billed by token usage.

The speech recognition model service transcribes only the content in a track that is identified as speech, and meters and bills based on that duration. Non-speech content is not metered or billed. Typically, the speech content duration is shorter than the original audio duration. Because whether speech content exists is determined by an AI model, the result may differ slightly from the actual situation.

transcript

string

The paragraph-level transcription result.

sentences

array

The sentence-level transcription result.

words

array

The word-level transcription result.

begin_time

integer

The start timestamp (ms).

end_time

integer

The end timestamp (ms).

text

string

The transcription result.

speaker_id

integer

The index of the current speaker, starting from 0, used to distinguish between different speakers.

This field appears in the recognition result only when speaker diarization is enabled.

punctuation

string

The punctuation predicted after the word, if any.

Key interfaces

Core resource (client.audio.asr)

Create a client with dashscope.Client, then use its client.audio.asr resource. All methods below return a Job.

Method

Method signature

Description

transcribe

def transcribe(
    file_urls: List[str],
    *,
    model: str = "qwen-audio-3.1-asr-flash-filetrans",
    parameters: Optional[Dict[str, Any]] = None,
    phrase_id: Optional[str] = None,
    timeout: float = 86400.0,
    submit_timeout: Optional[float] = None,
    poll_interval: float = 1.0,
    max_interval: float = 8.0,
    api_key: Optional[str] = None,
    workspace: Optional[str] = None,
) -> Job

Submit a task and wait synchronously for completion. The default model is qwen-audio-3.1-asr-flash-filetrans. Specify model explicitly to call another model.

jobs.create

def create(
    *,
    model: str,
    file_urls: List[str],
    parameters: Optional[Dict[str, Any]] = None,
    phrase_id: Optional[str] = None,
    timeout: Optional[float] = None,
    api_key: Optional[str] = None,
    workspace: Optional[str] = None,
) -> Job

Submit a task and return a Job containing task_id and status, without waiting for recognition to finish.

jobs.wait

def wait(
    job: Union[Job, str],
    *,
    poll_interval: float = 1.0,
    max_interval: float = 8.0,
    timeout: float = 86400.0,
    api_key: Optional[str] = None,
    workspace: Optional[str] = None,
) -> Job

Pass a Job or task ID and wait synchronously for completion. Set the initial and maximum polling intervals with poll_interval and max_interval, and the total waiting time with timeout. All values are in seconds.

jobs.fetch

def fetch(
    task_id: str,
    *,
    timeout: Optional[float] = None,
    api_key: Optional[str] = None,
    workspace: Optional[str] = None,
) -> Job

Query the task status and results once by task ID, without waiting for completion.

Additional interfaces: batch query task status / cancel tasks

For details, see Manage asynchronous tasks. It supports batch querying non-real-time speech recognition tasks submitted within the past 24 hours, and canceling tasks in the PENDING (queued) state.

Error codes

By default, a failed task raises DashScopeError. To receive a failed Job, set raise_on_error=False when creating the Client, and check job.status.

If you encounter an error, see Error codes to troubleshoot.

When a task contains multiple subtasks, the overall task status is marked as SUCCEEDED as long as at least one subtask succeeds. Check the subtask_status field to determine the result of each subtask.

Error response example:

{
    "task_id": "7bac899c-06ec-4a79-8875-xxxxxxxxxxxx",
    "task_status": "SUCCEEDED",
    "submit_time": "2024-12-16 16:30:59.170",
    "scheduled_time": "2024-12-16 16:30:59.204",
    "end_time": "2024-12-16 16:31:02.375",
    "results": [
        {
            "file_url": "{YOUR_AUDIO_URL}",
            "code": "InvalidFile.DownloadFailed",
            "message": "The audio file cannot be downloaded.",
            "subtask_status": "FAILED"
        }
    ],
    "task_metrics": {
        "TOTAL": 1,
        "SUCCEEDED": 0,
        "FAILED": 1
    }
}

FAQ

Features

Q: Is Base64-encoded audio supported?

Base64-encoded audio is not supported. Only audio at a publicly accessible URL can be recognized. Binary streams and local files cannot be recognized directly.

Q: How do I make an audio file available at a publicly accessible URL?

The typical steps are as follows. This is one approach; the exact process varies by storage product. We recommend that you upload the audio to Alibaba Cloud OSS:

1. Choose a storage and hosting method

For example:

  • Object storage service (recommended):

    • Use a cloud provider's object storage service (such as Alibaba Cloud OSS) to upload the audio file to a bucket and set it to public access.
    • Advantages: high availability, CDN acceleration support, and easy management.
  • Web server:

    • Place the audio file on a web server that supports HTTP/HTTPS access (such as Nginx or Apache).
    • Advantages: suitable for small projects or local testing.
  • Content delivery network (CDN):

    • Host the audio file on a CDN and access it through the URL that the CDN provides.
    • Advantages: accelerates file delivery and suits high-concurrency scenarios.

2. Upload the audio file

Upload the audio according to the storage or hosting method you chose. For example:

  • Object storage service:

    • Log in to the cloud provider's console and create a bucket.
    • Upload the audio file, and set its permission to public read or generate a temporary access link.
  • Web server:

    • Place the audio file in a designated directory on the server (such as /var/www/html/audio/).
    • Make sure the file is accessible over HTTP/HTTPS.

3. Generate a publicly accessible URL

For example:

  • Object storage service:

    • After the file is uploaded, the system automatically generates a public access URL (typically in the format https://<bucket-name>.<region>.aliyuncs.com/<file-name>).
    • For a friendlier domain name, bind a custom domain and enable HTTPS.
  • Web server:

    • The access URL is usually the server address plus the file path (such as https://your-domain.com/audio/file.mp3).
  • CDN:

    • After you configure CDN acceleration, use the URL that the CDN provides (such as https://cdn.your-domain.com/audio/file.mp3).

4. Verify that the URL works

Make sure the generated URL is accessible over the public network. For example:

  • Open the URL in a browser and check whether the audio file plays.
  • Use a tool (such as curl or Postman) to verify that the URL returns the correct HTTP response (status code 200).

When using the SDK, if audio files are stored in Alibaba Cloud OSS, temporary URLs with the oss:// prefix are not supported.

When using the RESTful API, if audio files are stored in Alibaba Cloud OSS, temporary URLs with the oss:// prefix are supported:

  • The temporary URL is valid for 48 hours and cannot be used after it expires. Do not use it in a production environment.
  • The API for obtaining an upload credential is limited to 100 QPS and does not support scaling out. Do not use it in production environments, high-concurrency scenarios, or stress testing scenarios.
  • For production environments, use a stable storage service such as OSS to ensure long-term file availability and avoid rate limiting issues.

Q: How long does it take to get the recognition result?

After a task is submitted, it enters the queued (PENDING) state. The queuing time depends on the queue length and the audio duration, so it cannot be stated exactly, but it is usually within a few minutes. In general, the longer the audio, the longer it takes.

Troubleshooting

If you encounter a code error, troubleshoot the issue based on the information in Error codes.

Q: Polling never returns a result?

This may be caused by throttling. Wait a moment and try again.

Q: Why can't the speech be recognized (no recognition result)?

Check that the audio format and sample rate are correct and meet the parameter constraints.

Use the ffprobe tool to get the audio container, codec, sample rate, channels, and other details:

ffprobe -v error -show_entries format=format_name -show_entries stream=codec_name,sample_rate,channels -of default=noprint_wrappers=1 input.xxx