Request body modelstring(Required) The model name. inputobject(Required) The input information. Properties messagesarray(object)(Required) The message list. It contains the audio to recognize and, optionally, conversation context that improves recognition accuracy. ImportantThe context feature improves the recognition accuracy of domain-specific terms. For usage, see Context enhancement. A request can include at most 5 context messages of each type (input_text and text). If you exceed this limit, only the 5 most recent messages are kept. The total context text per turn (the combined length of the text fields in the user and assistant messages) cannot exceed 400 characters, where each character counts as 1. Any excess is truncated from the end. ImportantWhen you include context, the message order in messages matters: context messages must be arranged by conversation turn. Within each turn, the user message (of type input_text) must come before the corresponding assistant message (of type text). The user message that contains input_audio must be the last item in the messages array. Properties rolestring(Required) The message role. Valid values:
user (Required): A user message. When type is input_audio, it holds the audio to recognize. When type is input_text, it holds recognition results from previous turns or a domain-specific word list (optional, used as context).
assistant (Optional, context): Replies from the large language model in previous turns.
contentarray(object)(Required) The message content list. Properties typestring(Required) The content type. Each request needs at least one message of type input_audio. Valid values:
input_audio (Required): The audio input to recognize (role is user). You must also pass the input_audio object.
input_text (Optional, context): Recognition results of the user's speech from previous turns, or a domain-specific word list (role is user). You must also pass the text field.
text (Optional, context): Replies from the large language model in previous turns (role is assistant). You must also pass the text field.
input_audioobject(Conditionally required) Required when type is input_audio. Properties datastring(Required) The audio data to recognize. For input requirements such as supported audio formats, file size limits, and duration limits, see Audio specifications. Two methods are supported:
- Audio file URL: Pass a publicly accessible URL to the audio file.
- Base64 Data URI: Pass the Base64-encoded audio data as a Data URI. The value is the
data:{MIME_TYPE};base64, prefix concatenated with the Base64-encoded audio data. Supported MIME types include audio/wav and audio/mp3.
Example (URL): https://example.com/audio/sample.wav Example (Base64): data:audio/wav;base64,{BASE64_ENCODED_DATA} textstring(Conditionally required) When type is input_text, enter the recognition results of the user's speech from previous turns or a domain-specific word list. When type is text, enter the large language model's replies from previous turns. Text length is measured in characters, where each character counts as 1. The combined length of the text fields across all messages in a single context turn cannot exceed 400 characters. Any excess is truncated from the end. parametersobject(Required) The model parameters. NoteText polishing is disabled by default and is not yet available for qwen-audio-3.0-asr-flash. qwen-audio-3.1-asr-flash supports native text polishing. Text polishing: While transcribing speech, the model removes meaningless filler words and stuttered repetitions, handles self-corrections, smooths out colloquial expressions, and standardizes punctuation and text formatting. The output is more concise, fluent, and readable while preserving the speaker’s final intent and key information as much as possible. Properties speaker_diarization_enabled boolean (Optional) NoteApplies only to qwen-audio-3.1-asr-flash. Specifies whether to enable speaker diarization. Default: false. When set to true, the response uses speaker_id to distinguish speakers and includes output.sentences. When diarization is enabled, keep_dialect and language_hints are ignored. keep_dialect boolean (Optional) NoteApplies only to qwen-audio-3.1-asr-flash. Specifies whether to preserve dialect expressions. Default: false. Set to false to transcribe dialect speech as standard Mandarin text, or true to preserve dialect expressions. formatstring(Required) The audio format. Set this to match your actual audio format. Supported values include wav, mp3, and opus. For details, see Audio specifications. sample_ratestring(Optional) The audio sample rate, in Hz. For example, 16000 means a 16 kHz sample rate. For details, see Audio specifications. vocabulary_idstring(Optional) 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. vocabularyobject(Optional) 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. language_hints array[string](Optional) The language codes to recognize. If the language is unknown in advance, omit this parameter to let the model detect it automatically. You can set up to 4 values. If you set more, only the first 4 take effect. Specifying language codes can improve recognition accuracy. 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
qwen-audio-3.1-asr-flash also supports the following language codes:
- tr: Turkish
- fa: Persian
- mr: Marathi
- ml: Malayalam
- ne: Nepali
- ky: Kyrgyz
- az: Azerbaijani
- ka: Georgian
- hy: Armenian
- sl: Slovenian
- sq: Albanian
- et: Estonian
- lv: Latvian
- lt: Lithuanian
- ca: Catalan
- eu: Basque
- gl: Galician
- or: Odia
- dv: Divehi
- as: Assamese
- ku: Kurdish
- tig: Tigre
- fy: Western Frisian
- ba: Bashkir
- be: Belarusian
- tt: Tatar
- ia: Interlingua
- mhr: Eastern Mari
- tok: Toki Pona
| The following examples use the configuration for the China (Beijing) region. Replace "{WorkspaceId}" with your actual workspace ID. The configuration differs across regions. Non-streamingcurl --location --request POST 'https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/api/v1/services/aigc/multimodal-generation/generation' \
--header "Authorization: Bearer $DASHSCOPE_API_KEY" \
--header "Content-Type: application/json" \
--header "X-DashScope-SSE: disable" \
--data '{
"model": "qwen-audio-3.1-asr-flash",
"input": {
"messages": [
{
"role": "user",
"content": [
{
"type": "input_audio",
"input_audio": {
"data": "{YOUR_AUDIO_URL}"
}
}
]
}
]
},
"parameters": {
"format": "wav",
"sample_rate": "16000"
}
}'
Streamingcurl --location --request POST 'https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/api/v1/services/aigc/multimodal-generation/generation' \
--header "Authorization: Bearer $DASHSCOPE_API_KEY" \
--header "Content-Type: application/json" \
--header "X-DashScope-SSE: enable" \
--data '{
"model": "qwen-audio-3.1-asr-flash",
"input": {
"messages": [
{
"role": "user",
"content": [
{
"type": "input_audio",
"input_audio": {
"data": "{YOUR_AUDIO_URL}"
}
}
]
}
]
},
"parameters": {
"format": "wav",
"sample_rate": "16000"
}
}'
With context - non-streamingcurl --location --request POST 'https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/api/v1/services/aigc/multimodal-generation/generation' \
--header "Authorization: Bearer $DASHSCOPE_API_KEY" \
--header "Content-Type: application/json" \
--header "X-DashScope-SSE: disable" \
--data @- <<'JSON'
{
"model": "qwen-audio-3.1-asr-flash",
"input": {
"messages": [
{
"role": "user",
"content": [
{
"type": "input_text",
"text": "Hello"
}
]
},
{
"role": "assistant",
"content": [
{
"type": "text",
"text": "Hello, I'm Qwen. How can I help you?"
}
]
},
{
"role": "user",
"content": [
{
"type": "input_audio",
"input_audio": {
"data": "{YOUR_AUDIO_URL}"
}
}
]
}
]
},
"parameters": {
"format": "wav",
"sample_rate": "16000"
}
}
JSON
With context - streamingcurl --location --request POST 'https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/api/v1/services/aigc/multimodal-generation/generation' \
--header "Authorization: Bearer $DASHSCOPE_API_KEY" \
--header "Content-Type: application/json" \
--header "X-DashScope-SSE: enable" \
--data @- <<'JSON'
{
"model": "qwen-audio-3.1-asr-flash",
"input": {
"messages": [
{
"role": "user",
"content": [
{
"type": "input_text",
"text": "Hello"
}
]
},
{
"role": "assistant",
"content": [
{
"type": "text",
"text": "Hello, I'm Qwen. How can I help you?"
}
]
},
{
"role": "user",
"content": [
{
"type": "input_audio",
"input_audio": {
"data": "{YOUR_AUDIO_URL}"
}
}
]
}
]
},
"parameters": {
"format": "wav",
"sample_rate": "16000"
}
}
JSON
Base64You can pass Base64-encoded data (Data URL) in the format data:<mediatype>;base64,<data>.
-
<mediatype>: The MIME type.
The value depends on the audio format. For example:
- WAV:
audio/wav
- MP3:
audio/mpeg
-
<data>: The Base64-encoded string of the audio.
Base64 encoding increases the data size. For audio file size and duration limits, see Audio specifications.
-
Example: data:audio/wav;base64,SUQzBAAAAAAAI1RTU0UAAAAPAAADTGF2ZjU4LjI5LjEwMAAAAAAAAAAAAAAA//PAxABQ/BXRbMPe4IQAhl9
import base64, pathlib
import os
import requests
# Replace with the path to your own audio file and make sure it meets the audio requirements
file_path = pathlib.Path("{YOUR_AUDIO_FILE}")
base64_str = base64.b64encode(file_path.read_bytes()).decode()
data_uri = f"data:audio/wav;base64,{base64_str}"
url = "https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/api/v1/services/aigc/multimodal-generation/generation"
headers = {
"Authorization": f"Bearer {os.environ['DASHSCOPE_API_KEY']}",
"Content-Type": "application/json",
"X-DashScope-SSE": "disable",
}
payload = {
"model": "qwen-audio-3.1-asr-flash",
"input": {
"messages": [
{
"role": "user",
"content": [
{
"type": "input_audio",
"input_audio": {
"data": data_uri,
},
}
],
}
]
},
"parameters": {
"format": "wav",
"sample_rate": "16000",
},
}
response = requests.post(url, headers=headers, json=payload)
print(response.status_code)
print(response.json())
Inline hotwordscurl --location --request POST 'https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/api/v1/services/aigc/multimodal-generation/generation' \
--header "Authorization: Bearer $DASHSCOPE_API_KEY" \
--header "Content-Type: application/json" \
--header "X-DashScope-SSE: disable" \
--data '{
"model": "qwen-audio-3.1-asr-flash",
"input": {
"messages": [
{
"role": "user",
"content": [
{
"type": "input_audio",
"input_audio": {
"data": "{YOUR_AUDIO_URL}"
}
}
]
}
]
},
"parameters": {
"format": "wav",
"sample_rate": "16000",
"vocabulary": {"John Smith": 5, "Jane Doe": 5}
}
}'
|