Qwen-LiveTranslate Python SDK - API reference
Use the DashScope SDK for Python to call Qwen-LiveTranslate for real-time speech translation.
Prerequisites
-
Install the SDK. Make sure that your DashScope SDK version is 1.25.6 or later.
Model Studio has released a workspace-specific domain for the Singapore region: wss://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com. The new dedicated domain delivers superior performance and higher stability for inference requests. We recommend migrating from wss://dashscope-intl.aliyuncs.com to the new domain.
{WorkspaceId} is your workspace ID, which can be found on the Workspace Details page in the Model Studio console. The existing domain remains fully functional.
Request parameters
-
Set the following parameters in the constructor of the
OmniRealtimeConversationclass.Parameter
Type
Required
Description
modelstrYes
The name of the model to use. Set this to
qwen3.5-livetranslate-flash-realtime(recommended).qwen3-livetranslate-flash-realtimeis a legacy model.callbackYes
A callback instance to handle server-side events.
urlstrYes
The service endpoint for real-time translation:
-
China (Beijing):
wss://dashscope.aliyuncs.com/api-ws/v1/realtime -
Singapore:
wss://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api-ws/v1/realtime. Replace {WorkspaceId} with your workspace ID.
-
-
Set the following parameters using the
update_sessionmethod of theOmniRealtimeConversationclass.Parameter
Type
Required
Description
output_modalitiesList[MultiModality]No
The output format for translation results.
Default:
[MultiModality.TEXT, MultiModality.AUDIO].Valid values:
-
[MultiModality.TEXT]: Outputs text only -
[MultiModality.TEXT, MultiModality.AUDIO]: Outputs text and audio
voicestrNo
The voice for audio output.
Default:
-
Qwen3.5-LiveTranslate-Flash-Realtime:
Tina -
Qwen3-LiveTranslate-Flash-Realtime:
Cherry
Valid values: Supported voices.
input_audio_transcription_modelstrNo
Set this parameter to
qwen3-asr-flash-realtimeto receive speech recognition results for the source language.translation_paramsTranslationParamsNo
Translation settings (target language and hotwords).
-
-
Set the following parameters in the constructor of the
TranslationParamsclass.Parameter
Type
Required
Description
languagestrNo
The target language for translation.
Default:
en.Valid values: Supported languages.
corpusTranslationParams.CorpusNo
A hotword mapping to improve translation accuracy for specific terms.
corpus.phrasesdictNo
The hotword mapping table where keys are source terms and values are target translations.
Example:
{'Inteligencia Artificial': 'Artificial Intelligence'}
Key interfaces
OmniRealtimeConversation class
Import: from dashscope.audio.qwen_omni import OmniRealtimeConversation
|
Method signature |
Server-side response event (sent via callback) |
Description |
|
Session created Session configuration updated |
Connect to the server. |
|
Session configuration updated |
Update session configuration. Call immediately after connecting. If you do not call this method, default configurations apply. |
|
The server completes the speech translation and ends the session |
End the session. The server completes final translation processing. |
|
None |
Send Base64-encoded audio chunks to the server. Speech detection and translation are automatic. |
|
None |
Stop the task and close the connection. |
|
None |
Get the session ID. |
|
None |
Get the last response ID. |
Callback interface (OmniRealtimeCallback)
Receive server events and data through callbacks.
Inherit this class and implement its methods to handle events from the server.
Import: from dashscope.audio.qwen_omni import OmniRealtimeCallback
|
Method signature |
Parameters |
Description |
|
None |
Called when the WebSocket connection opens. |
|
message: Server-side event |
Called when the server sends an event. |
|
close_status_code: The status code. close_msg: The log message when the WebSocket connection is closed. |
Called when the WebSocket connection closes. |
Complete example
This example records microphone audio and translates it in real time.