Qwen-Audio is an end-to-end real-time voice interaction model for low-latency voice conversations. Use cases include voice assistants, intelligent customer service, and AI companions.
Overview
Qwen-Audio converts real-time audio to speech and text over a full-duplex connection, with streaming input and streaming output.
In addition to WebSocket, this model supports AOQ and WebRTC. For client-side integration that prioritizes stable latency, interaction under poor network conditions, and noise suppression and echo cancellation for real-time full-duplex communication, consider AOQ first. For protocol comparison and selection, see the API reference.
- Function Calling support lets the model decide when to invoke external tools for additional information
- Web search support lets the model decide when to retrieve up-to-date information and return search result sources; web search and Function Calling can be enabled together
- Conversation context management: create, retrieve, and delete conversation items to inject historical context or remove irrelevant items
- Expressive voice output that dynamically adjusts tone, pacing, and emotion based on the conversation context
- Support for system voices and cloned voices; use Voice Cloning to create a custom AI voice for speech output
qwen-audio-3.1-realtime-plus, qwen-audio-3.1-realtime-flash, qwen-audio-3.0-realtime-plus, and qwen-audio-3.0-realtime-flash.
- Three interaction modes: acoustic VAD (server_vad), intelligent semantic turn detection (smart_turn), and manual control (push-to-talk)
- In smart_turn mode, the model combines acoustic perception and semantic understanding to determine turn boundaries, so filler sounds such as "uh" or "hmm" don't interrupt the conversation
- Speaker enhancement in smart_turn mode: pass pre-recorded audio from a target user so the model can lock onto that speaker during duplex conversations, effectively blocking other voices and background noise
How it works
Qwen-Audio uses a full-duplex connection with an event-driven architecture. The client and server exchange data simultaneously over a persistent connection: the client continuously streams microphone audio while the server returns speech and text responses in real time. The entire interaction is event-driven: the client sends events such as session.update and input_audio_buffer.append, and the server responds with events such as response.audio.delta and response.done. No polling is required.
A typical connection lifecycle is: establish WebSocket connection, send session.update to configure session parameters, stream audio and receive responses, then close the connection.
Audio format
| Direction | Format | Specification |
|---|---|---|
| Input (client to server) | PCM | 16 kHz sample rate, 16-bit depth, mono |
| Output (server to client) | PCM | 24 kHz sample rate, 16-bit depth, mono |
Supported languages
Real-time voice conversations support the following languages and Chinese varieties:
- Languages for
qwen-audio-3.1-realtime-plusandqwen-audio-3.1-realtime-flash: German (de), English (en), Spanish (es), French (fr), Indonesian (id), Italian (it), Japanese (ja), Korean (ko), Portuguese (pt), Russian (ru), Chinese (zh), Thai (th), Vietnamese (vi), and Arabic (ar). - Languages for
qwen-audio-3.0-realtime-plusandqwen-audio-3.0-realtime-flash: German (de), English (en), Spanish (es), French (fr), Indonesian (id), Italian (it), Japanese (ja), Korean (ko), Portuguese (pt), Russian (ru), and Chinese (zh). - Chinese varieties: Mandarin, Cantonese, Chongqing, Northeastern, Gansu, Guizhou, Zhejiang, Hebei, Henan, Hubei, Hunan, Jiangxi, Ningbo, Ningxia, Qingdao, Shaanxi, Shanxi, Shandong, Shanghainese, Sichuan, and Yunnan.
qwen-audio-3.1-realtime-plus or qwen-audio-3.1-realtime-flash, you can use session.input_audio_transcription.language and session.output_audio.language to specify the source language of the input audio and the target language of the output audio, respectively. For the valid language codes for each parameter, see Client events. Of the two, session.output_audio.language applies to speech synthesis (TTS): the model makes a best effort to produce speech in the target language, but this is not guaranteed, and the language of the response text is not changed.
Context capacity
The model maintains conversation history. When the number of turns or cumulative audio duration exceeds the following limits, earlier history is automatically discarded. The maximum duration is the upper limit of cumulative audio the model's context can retain.
| Model | Max audio turns | Max audio duration |
|---|---|---|
| qwen-audio-3.1-realtime-plus | 50 | 300 seconds |
| qwen-audio-3.1-realtime-flash | 50 | 300 seconds |
| qwen-audio-3.0-realtime-plus | 50 | 300 seconds |
| qwen-audio-3.0-realtime-flash | 50 | 300 seconds |
max_history_turns parameter controls the number of historical QA turns the model uses for inference. The default is 20, and the valid range is 1-50. For configuration details, see History turn control.
For guidance on choosing between multimodal models, see Omni-modal.
Prerequisites
- Obtain an API key and configure it as an environment variable.
- To use the AOQ protocol, download and integrate the AOQ client SDK. For details, see SDK overview.
Quick start
The basic WebSocket examples below use qwen-audio-3.1-realtime-plus with the system voice longanqian_v3.1 set explicitly. To migrate from 3.0 Plus, update the model query parameter in the URL and select a matching voice from Voice configuration. The WebSocket event protocol is unchanged.
Follow these steps to start a real-time voice conversation with the Qwen-Audio model.
- WebSocket native
For the WebSocket event interaction sequence between the client and server in each mode, see Event interaction flow.
server_vad mode. Before running, install the required dependencies:macOS
realtime_quickstart.py:python realtime_quickstart.py and speak into your microphone to start a real-time conversation. The server automatically detects speech activity and triggers responses.Complete exampleThe following example extends the basic conversation with voice interruption handling and echo cancellation. Create the two files in the same directory:B64PCMPlayer.py
B64PCMPlayer.py
realtime_demo.py
realtime_demo.py
If
websockets is earlier than version 11, change additional_headers to extra_headers in the code, or upgrade: pip install --upgrade websockets.python realtime_demo.py and speak into your microphone to start a real-time conversation. The system automatically detects speech activity and triggers responses.The examples above use server_vad mode, where the server automatically detects speech activity. To use smart_turn / smart_turn_v2 (intelligent semantic turn detection; smart_turn_v2 is recommended) or push-to-talk (manual control) mode, see Interaction modes.
Session configuration
Interaction modes
Qwen-Audio supports three interaction modes: server_vad (acoustic VAD automatically detects the start and end of speech), smart_turn (intelligent semantic turn detection combines acoustic and semantic signals; smart_turn_v2 is recommended), and push-to-talk (manual client control). For details and the event interaction sequence, including sequence diagrams, see Interaction modes.
turn_detection can only be set before the first audio is sent (IDLE state). To switch interaction modes mid-session, close and re-establish the connection.turn_detection field in a session.update event:
- server_vad:
- smart_turn / smart_turn_v2:
smart_turn_v2 (recommended): Builds on smart_turn to better understand conversation context and interaction intent in multi-speaker settings. Reduces unintended responses or interruptions caused by bystanders or unrelated interjections. Set type to smart_turn to keep using the original intelligent turn detection.
- push-to-talk:
manual_funchat.py
manual_funchat.py
System instructions
Use the instructions parameter to define the model's role, response style, and behavioral preferences. Configure this parameter in session.update to apply it to the entire session.
- Define a clear role identity (for example, "You are an intelligent voice assistant" or "You are an English conversation tutor"), and optionally include details such as name or gender.
- Specify a conversational tone and phrasing style, while emphasizing that a natural tone does not compromise content completeness — details, numbers, and specific recommendations must still be included, just expressed in a relaxed, natural way.
- Instruct the model to account for all context constraints in the conversation (such as budget, preferences, restrictions, or prior agreements). When multiple conditions apply, address each one and omit no critical information.
- Control output format: unless the user requests otherwise, avoid emoji and other special characters and Markdown formatting. Output plain text to ensure natural TTS playback.
- Define response strategy: keep simple greetings and casual exchanges brief and natural; for reasoning, multi-condition problems, recommendation lists, or safety advice, prioritize completeness — ensure key information (such as prices, locations, and conditions) is fully present, with no unnecessary preamble, repetition, or filler.
- Set a follow-up strategy: follow the principle of "answer the user's current question first, then naturally pose a follow-up at the end to advance the conversation." Ask only one question at a time; do not ask multiple questions in a row or repeatedly confirm.
instructions configuration for general voice conversation scenarios. It covers role definition, conversational style, format control, and follow-up strategy. Use it directly or adapt it to your needs:
instructions examples cover a range of persona styles. Choose one that fits your use case or customize it further:
- Daisy (Sweet & Cool Companion):
- Len (Cool & Sharp-Tongued):
- Mochen (Calm & Charismatic):
- Hannibal (Elegant & Incisive):
- Heizi (Northeastern Buddy):
Voice configuration
Use the voice parameter to set the TTS voice for model responses. Both system voices and cloned voices are supported. The default voice is longanqian_v3.1 for 3.1 Plus/Flash and longanqian for 3.0 Plus/Flash.
The voice can only be set in the first
session.update. The field is ignored in subsequent session.update calls.| Model | System voice IDs |
|---|---|
qwen-audio-3.1-realtime-plus, qwen-audio-3.1-realtime-flash | Supports longanqian_v3.1 and the union of the voice lists for qwen-audio-3.1-tts-plus and qwen-audio-3.1-tts-flash. See these lists for voice IDs and audio samples. |
qwen-audio-3.0-realtime-plus, qwen-audio-3.0-realtime-flash | longanqian, longanlingxin, longanlingxi, longanxiaoxin, longanlufeng |
target_model to qwen-audio-3.1-realtime-plus, qwen-audio-3.1-realtime-flash, qwen-audio-3.0-realtime-plus, or qwen-audio-3.0-realtime-flash. Then set the voice parameter to the returned voice_id.
Audio output speaking rate
In session.update, set speech_rate in the session object to control the speaking rate of model audio output. Range: [0.5, 2.0]. Default: 1.0. Lower values slow the speech; higher values speed it up. Supported by qwen-audio-3.1-realtime-plus, qwen-audio-3.1-realtime-flash, qwen-audio-3.0-realtime-plus, qwen-audio-3.0-realtime-flash. This example sets the parameter to 1.2:
Output modalities
Use the modalities parameter to control the model's output types:
["audio", "text"](default): outputs both speech and text.["text"]: outputs text only, without speech. Suitable for debugging, logging, or scenarios that only need text responses.
response.modalities field in response.create to override the modality setting for a single response.
VAD configuration
Set the VAD parameters in session.turn_detection. threshold applies to server_vad, smart_turn, and smart_turn_v2. silence_duration_ms applies only to server_vad.
| Parameter | Type | Description |
|---|---|---|
threshold | float | VAD sensitivity. Lower values increase VAD sensitivity, making it easier to detect faint sounds (including background noise) as speech. Higher values decrease sensitivity, requiring clearer and louder speech to trigger detection. Range: [-1.0, 1.0]. Default: 0.5. |
silence_duration_ms | integer | Minimum silence duration (in milliseconds) after speech ends before triggering a model response. Lower values produce faster responses but may cause false triggers during brief pauses. Range: [200, 6000]. Default: 800. Recommended range for conversations: 400-800. |
History turn control
This section applies to qwen-audio-3.1-realtime-plus, qwen-audio-3.1-realtime-flash, qwen-audio-3.0-realtime-plus, and qwen-audio-3.0-realtime-flash.
Use the max_history_turns parameter to control how many historical QA turns the model references during inference. Higher values let the model review more conversation history for better context understanding, but increase token consumption and inference latency.
max_history_turns: 1-50. Default: 20.
Tuning tips:
- Short conversations (such as quick Q&A): set a lower value (for example, 5-10) to reduce latency.
- Long conversations (such as multi-turn customer service): set a higher value (for example, 30-50) to help the model understand the full context.
Advanced features
Function Calling
Qwen-Audio supports Function Calling, which lets the model decide when to invoke external tools based on the conversation context.
1. Register tools
Configure tools through session.update:
response.function_call_arguments.done, run the tool on the client and send the result back via conversation.item.create:
response.create to have the model generate a response based on the tool result:
A single response can contain multiple
function_call items, and may include both regular messages and function calls. Function call content isn't sent to TTS for playback.realtime_demo.py from the quick start. Make sure B64PCMPlayer.py is in the same directory before running.
realtime_fc_demo.py
realtime_fc_demo.py
python realtime_fc_demo.py and speak into your microphone to try real-time conversations with Function Calling. For example, ask "What's the weather in Hangzhou?" or "How much is a train ticket from Beijing to Shanghai?" and the model automatically invokes the corresponding tool and responds with the result.
Web search
Enable web search to answer questions that need current information, such as weather forecasts and news. Web search is disabled by default. Once enabled, the model decides when to search; it does not search on every turn.
Web search and Function Calling can be enabled in the same session for qwen-audio-3.1-realtime-plus, qwen-audio-3.1-realtime-flash, qwen-audio-3.0-realtime-plus, and qwen-audio-3.0-realtime-flash.
For billing, see the
agent policy in billing rules.session.update event with the following parameters in session:
enable_search: Set totrueto enable web search.search_options.enable_source: Set totrueto return search result sources.
tools definitions to the session object above. For tool definitions and how to return tool results, see Function Calling.
For parameter details, see session.update.
2. Read search sources and usage
Replies arrive through the usual text and audio events. After a search, read the following fields from the response object in response.done:
search_info.search_results: The source list. Each entry contains a source number (index), title (title), and URL (url).usage.plugins.search.count: The search count. Do not use the number of sources as the search count.usage.plugins.search.strategy: The search policy, which isagent.
Conversation context management
Qwen-Audio lets you manage conversation items in the context through client events. Use this to inject historical context, add text information, or remove irrelevant conversation items.
-
Create a conversation item (
conversation.item.create): inserts a conversation item into the context. The following threeitem.typevalues are supported:message: a regular conversation message. Specifyrole(system,user, orassistant) and acontentarray. Use this to inject conversation history or system instructions.function_call: a function call request. Specifycall_id,name, andarguments(JSON string). Typically generated by the server, but the client can also use this to inject historical function call records.function_call_output: a tool execution result. Specifycall_idandoutput(JSON string). After receiving afunction_call, run the tool on the client and return the result with this type.
previous_item_idparameter specifies the existing conversation item after which to insert the new item. This lets you insert content at any position in the conversation history. If omitted, the new item is appended to the end.- Insert a user message at a specific position:
- Return a Function Calling result:
If the
item.id specified in conversation.item.create already exists in the conversation, an error is returned.- Retrieve a conversation item (
conversation.item.retrieve): queries a conversation item stored on the server. For audio-type content, only the transcription text is returned, not the raw audio data.
- Delete a conversation item (
conversation.item.delete): removes a specific item from the conversation context.
Ambient audio transcription
smart_turn / smart_turn_v2 modes only. When VAD detects speech activity but semantic analysis determines it isn't a valid turn (such as noise or filler sounds like "uh" or "hmm"), the server doesn't trigger a conversation turn. Instead, it sends the ASR result to the client as an ambient_audio_transcription event. This transcription isn't written to the conversation context.
delta and completed phases. Use this event to implement ambient audio monitoring or conversation scene awareness.
Speaker enhancement
smart_turn / smart_turn_v2 modes only. Pass pre-recorded audio URLs from the target user in session.update. The model will lock onto that speaker during duplex conversations, effectively ignoring other voices and background noise, enabling fluid duplex interactions in open environments.
Configuration: pass publicly accessible voiceprint audio URLs in turn_detection.voiceprint_audio_urls within the first session.update.
- Up to 5 URLs. Audio must be 16 kHz PCM or WAV format.
- This parameter only takes effect in the first
session.update. The field is ignored in subsequent calls.
voiceprint_audio_list.in_progress: registration has started. Sent beforesession.updated, carryingitem_id.voiceprint_audio_list.completed: registration succeeded. Theitem_idmatches the one inin_progress.voiceprint_audio_list.failed: registration failed, with areasonfield describing the error (for example, audio URL is not accessible). A registration failure does not block the ongoing conversation.
Going live
Set up fault tolerance
- Client reconnection: implement automatic reconnection to handle network jitter. Set a reconnection signal in the
on_errorcallback and use exponential backoff (for example, wait 1s, 2s, 4s) for retries. - Error classification: client errors (
invalid_request_error) don't disconnect the session; log them or adjust parameters. Server errors (server_error) terminate the connection and require reconnection. - Interruption handling: in server_vad / smart_turn / smart_turn_v2 modes, new user speech automatically interrupts the model's ongoing response (
response.donereturnsstatus=cancelled). Wheninput_audio_buffer.speech_startedis received, immediately clear the local playback buffer to avoid audio overlap.
Connection lifecycle
A typical WebSocket session follows this lifecycle:
- Connect: the client initiates a WebSocket connection and the server returns a
session.createdevent. - Configure: the client sends
session.updateto set the interaction mode, voice, tools, and other parameters. Complete this step before sending any audio. - Interact: the client continuously streams audio (
input_audio_buffer.append). The server performs inference based on VAD detection or manual triggers and returns speech and text in a streaming fashion. - Close: the client closes the WebSocket connection. The server may also disconnect if the connection is idle for too long.
To keep the final turn’s input transcript, you can wait for the transcription completion or transcription failure event for the corresponding
item_id before closing. response.done marks the end of the model response; the transcript may arrive later.Latency optimization
- Audio chunk size: send about 100 ms of audio data per chunk (16 kHz x 16 bit x mono = 3,200 bytes per chunk). This balances real-time performance with network efficiency.
- Streaming playback: start playing audio as soon as
response.audio.deltaarrives. Don't wait forresponse.doneto play the full response. - Clear buffer on interruption: when
input_audio_buffer.speech_startedis received, immediately clear the local playback buffer to prevent stale audio from continuing to play.
Supported models and regions
- Singapore
- China North 2 (Beijing)
Use a Singapore region API key when calling the following models:
- qwen-audio-3.1-realtime-plus
- qwen-audio-3.1-realtime-flash
- qwen-audio-3.0-realtime-plus
- qwen-audio-3.0-realtime-flash