Python SDK
The key interfaces and request parameters for Qwen-Omni real-time using the DashScope Python SDK.
Prerequisites
Your SDK version must be 1.25.17 or later. Before you start, see Real-time multimodal interaction flow.
Getting started
Download the sample code from GitHub. Three calling methods are available:
-
Audio conversation example: Captures real-time audio input from the microphone, enables VAD mode to automatically detect the start and end of speech, and supports voice interruption.
enable_turn_detectionparameter must be set to True.We recommend that you use headphones for audio playback to prevent echoes from triggering voice interruption.
-
Audio and video conversation example: Captures real-time audio and video input from the microphone and camera, enables VAD mode to automatically detect the start and end of speech, and supports voice interruption.
enable_turn_detectionparameter must be set to True.We recommend that you use headphones for audio playback to prevent echoes from triggering voice interruption.
-
Local call: Uses local audio and images as input and enables Manual mode, which lets you manually control the sending pace.
enable_turn_detectionparameter must be set to False.
Request parameters
Set the following request parameters in the constructor (__init__) of the OmniRealtimeConversation class.
|
Parameter |
Type |
Description |
|
model |
str |
The Qwen-Omni model to use. See Model list. |
|
callback |
Callback instance that handles server-side events. |
|
|
url |
str |
The call address:
Replace |
Alibaba Cloud Model Studio has released workspace-specific domains for the China (Beijing) and Singapore regions. The new dedicated domains deliver superior performance and higher stability for inference requests. We recommend migrating to the new domains:
China (Beijing): from
wss://dashscope.aliyuncs.comtowss://{WorkspaceId}.cn-beijing.maas.aliyuncs.comSingapore: from
wss://dashscope-intl.aliyuncs.comtowss://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com
{WorkspaceId} is your workspace ID, which can be found on the Workspace Details page in the Alibaba Cloud Model Studio console. The existing domain remains fully functional.
Configure the following request parameters with the update_session method.
|
Parameter |
Type |
Description |
|
output_modalities |
list[MultiModality] |
The model output modality. Set to [MultiModality.TEXT] for text only, or [MultiModality.TEXT, MultiModality.AUDIO] for both audio and text. |
|
voice |
str |
The voice for audio output. For supported voices, see Voice list. Default voices:
|
|
input_audio_format |
AudioFormat |
The format of the user's input audio. Currently only supports |
|
output_audio_format |
AudioFormat |
The format of the model's output audio. Currently only supports |
|
smooth_output |
bool |
This parameter is supported only by the Qwen3-Omni-Flash-Realtime series.
|
|
instructions |
str |
A system message that sets the model's objective or role. For example: You are an AI agent for a five-star hotel. Answer customer questions about room types, facilities, prices, and booking policies. Be accurate and friendly. Always respond with a professional and helpful attitude. Do not provide unverified information or information outside the hotel's scope of services. |
|
enable_input_audio_transcription |
bool |
Enables speech recognition for input audio. |
|
input_audio_transcription_model |
str |
Speech recognition model for input audio transcription. The value is always qwen3-asr-flash-realtime. This parameter is not configurable. |
|
turn_detection_type |
str |
The Voice Activity Detection (VAD) type. Valid values:
|
|
turn_detection_threshold |
float |
VAD detection threshold. Increase in noisy environments and decrease in quiet environments.
Default: 0.2. Valid values: [-1.0, 1.0]. |
|
turn_detection_silence_duration_ms |
int |
Silence duration that indicates end of speech. If exceeded, the model triggers a response. Default: 800. Valid values: [200, 6000]. |
|
turn_detection_param |
dict |
Additional Example: |
|
enable_search |
bool |
This parameter takes effect only when you use the Qwen3.5-Omni-Realtime series model. Enables web search. Default: Tool calling (tools) and web search (enable_search) are incompatible. You cannot enable both at the same time. |
|
search_options |
object |
Web search options. Takes effect only when Currently, you can only set |
|
tools |
list[dict] |
This parameter takes effect only when you use the Qwen3.5-Omni-Realtime series model. Tool definitions. When provided, the model can call external tools to respond to user questions. If a tool is called, the model does not generate audio and only returns the tool calling parameters. Each tool is a dictionary that contains the following fields:
|
|
temperature |
float |
Sampling temperature that controls content diversity. Higher values produce more diverse content; lower values produce more deterministic content. Valid values: [0, 2). Because both temperature and top_p control content diversity, we recommend that you set only one of them.
|
|
top_p |
float |
Probability threshold for nucleus sampling that controls content diversity. Higher values produce more diverse content; lower values produce more deterministic content. Valid values: (0, 1.0]. Because both temperature and top_p control content diversity, we recommend that you set only one of them. Default top_p values:
|
|
top_k |
integer |
Candidate set size for sampling. For example, 50 means only the 50 highest-scoring tokens form the candidate set. Larger values increase randomness; smaller values increase determinism. Set to None or a value greater than 100 to disable top_k and use only top_p. The value must be greater than or equal to 0. Default top_k values:
|
|
max_tokens |
integer |
Maximum number of tokens to return.
Default and maximum values equal the model's maximum output length. See the Model Studio console for details. Use max_tokens to limit output length for generating summaries, keywords, controlling costs, or reducing response time.
|
|
repetition_penalty |
float |
Controls repetition in generated sequences. Higher values reduce repetition. 1.0 means no penalty. Must be greater than 0. Default repetition_penalty values:
|
|
presence_penalty |
float |
Controls content repetition in model output. Valid values: [-2.0, 2.0]. Positive values reduce repetition; negative values increase it. Default presence_penalty values:
Scenarios: Higher values suit scenarios requiring diversity or creativity, such as creative writing or brainstorming. Lower values suit scenarios requiring consistency or technical precision, such as technical documents.
|
|
seed |
integer |
Makes generation more deterministic, ensuring consistent results across runs. Passing the same seed with identical parameters produces the same result as much as possible. Valid values: 0 to 231−1. Default value: -1.
|
Key interfaces
OmniRealtimeConversation class
Import with from dashscope.audio.qwen_omni import OmniRealtimeConversation.
|
Method signature |
Server-side response event (delivered via callback) |
Description |
|
Session created Session configuration updated |
Creates a connection with the server. |
|
Session configuration updated |
Updates session configuration. For parameter details, see Request parameters. After connecting, the server returns default session configurations. Call this method immediately after connecting to update settings. When the server receives the |
|
None |
Appends Base64-encoded audio to the cloud input buffer. The buffer is temporary storage that can be written to and committed later.
|
|
None |
Adds Base64-encoded image data to the cloud video buffer. Accepts local images or real-time video stream captures. Image input limits:
|
|
Deletes the audio received by the server |
Deletes the audio from the current cloud buffer. |
|
Server received the committed audio |
Commits audio and video from the cloud buffer. Returns an error if the buffer is empty.
Note:
|
|
Server starts generating a response New output content is available in the response Conversation item created New output content added to the assistant message item response.audio_transcript.delta Incrementally generated transcribed text Incrementally generated audio from the model response.audio_transcript.done Text transcription completed Audio generation completed Streaming of text or audio content for the assistant message is complete Streaming of the entire output item for the assistant message is complete Response completed |
Instructs the server to create a model response. When you configure a session in "turn_detection" mode, the server automatically creates a model response. |
|
None |
Cancels the in-progress response. If there is no response to cancel, the server responds with an error. |
|
None |
Sends a The item parameter is a dictionary that must contain the following fields:
|
|
None |
Terminates the task and closes the connection. |
|
None |
Gets the session_id of the current task. |
|
None |
Gets the response_id of the last response. |
Callback interface (OmniRealtimeCallback)
The server returns response events and data via callbacks. Implement callback methods to process server responses.
Import with from dashscope.audio.qwen_omni import OmniRealtimeCallback.
|
Method |
Parameters |
Return value |
Description |
|
|
None |
None |
Called after the server connection is established. |
|
message: A server-side response event. |
None |
Contains interface call responses and model-generated text and audio. See Server-side events. |
|
close_status_code: The status code for closing the WebSocket. close_msg: The closing message for the WebSocket. |
None |
Called after the server closes the connection. |
FAQ
Q: How do I align input audio and images?
The Qwen-Omni real-time model uses the audio stream as the input timeline. Images are inserted into the audio stream based on the time they are sent. You can add images at any point in the audio timeline.
In real-time interaction scenarios, you can enable or disable video input at any time.
Q: What is the recommended frequency for inputting images and audio?
In real-time interaction scenarios, we recommend sending images at a frame rate of 1 or 2 fps and sending audio in 100 ms packets.
Q: What are the differences between the two modes of the turn_detection switch?
When turn_detection is enabled, it supports two modes: server_vad and semantic_vad:
-
Enable "turn_detection":
-
Input state: The cloud-based VAD detects the end of a sentence in the input audio and immediately triggers Qwen-Omni inference to return the reply text and speech.
-
Response state: In this state, you can continue to send audio and video input without interruption while the model is responding. After the response is complete, the state returns to the input state to await the next speech input.
-
Interruption: If the user starts speaking while the model is responding, an interruption is triggered. The service immediately stops the current response and switches to the input state.
-
-
Disable "turn_detection":
-
You must manually determine the end of a round of audio and video input and trigger Qwen-Omni inference to obtain a response using commit and create_response.
-
While the model is responding, you must stop sending audio and video input. You can resume input for the next round only after the model has finished responding.
-
You must use the cancel_response method to interrupt the model's response.
-
Note that when turn_detection is enabled, you can still actively trigger a response using commit and create_response, and actively interrupt it using cancel_response.
Q: Why do I need to select another model for input_audio_transcription?
Qwen-Omni real-time is an end-to-end multimodal model. Its text output is a response to the input, not a direct transcription of the input audio. A separate ASR model is required for transcription. Currently, the model is determined by the built-in configuration and is not configurable.