This document describes how to use DashScope Java SDK to call the real-time audio and video translation (Qwen-LiveTranslate-Realtime) model.
Prerequisites
- Install the SDK and make sure the DashScope SDK version is 2.22.5 or later.
- Get and configure an API key.
- Learn about Real-time speech/audio and video translation - Qwen.
Quick start
The following example shows how to record audio from a microphone in real time and translate it.
Sample code for real-time microphone translation
Sample code for real-time microphone translation
wss://WorkspaceId.cn-beijing.maas.aliyuncs.com/api-ws/v1/realtimewss://WorkspaceId.ap-southeast-1.maas.aliyuncs.com/api-ws/v1/realtimeRequest parameters
-
The following parameters are set through the chained methods of
OmniRealtimeParam.Click to view the sample code
Parameter Type Required Description modelStringYes Specifies the name of the model to use. We recommend qwen3.5-livetranslate-flash-realtime.urlStringYes Real-time translation service endpoint: - China (Beijing):
wss://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/api-ws/v1/realtime - Singapore:
wss://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api-ws/v1/realtime
{WorkspaceId}with your actual workspace ID.apikeyStringNo Sets the API key. - China (Beijing):
-
The following parameters are set through the chained methods of
OmniRealtimeConfig.Click to view the sample code
Extra session parameters Some session parameters have no dedicated SDK configuration method. Pass them throughParameter
Type
Required
Description
modalitiesList<OmniRealtimeModality>No
Model output modalities.
Default value:
[OmniRealtimeModality.AUDIO, OmniRealtimeModality.TEXT].Available values:
[OmniRealtimeModality.TEXT]: Text output only[OmniRealtimeModality.AUDIO, OmniRealtimeModality.TEXT]: Outputs text and audio
voiceStringYes
Voice for the generated audio.
Default value:
The default voice for Qwen3.5-LiveTranslate-Flash-Realtime is:
Tina
Available values: see supported voices.
inputAudioFormatOmniRealtimeAudioFormatNo
Input audio format.
Default value:
OmniRealtimeAudioFormat.PCM_16000HZ_MONO_16BIT.outputAudioFormatOmniRealtimeAudioFormatNo
Output audio format.
Default value:
OmniRealtimeAudioFormat.PCM_24000HZ_MONO_16BIT.InputAudioTranscriptionStringNo
Input audio transcription model. You must set this parameter if you want to output the source-language transcription.
Available value:
qwen3-asr-flash-realtime.translationConfigOmniRealtimeTranslationParamNo
Translation-related configuration.
enableTurnDetectionbooleanNo
Whether to enable VAD (Voice Activity Detection).
Default value:
true, which enables VAD mode, where the server automatically detects speech start and end and automatically triggers translation.OmniRealtimeConfig.builder().parameters(Map). The Map entries are written directly tosession. For example, prepare these parameters to enable real-time voice cloning:In the existing configuration builder chain, set.voice("default")and add.parameters(parameters). Keep the existing language and audio settings, then callconversation.updateSession(config). See Voice cloning for the supported frequency and voice combinations. -
The following parameters are set through the chained methods of OmniRealtimeTranslationParam.
Click to view the sample code
Parameter
Type
Required
Description
languageStringNo
Target language code for translation.
Default value:
en.Available values: see supported languages.
corpusOmniRealtimeTranslationParam.CorpusNo
Custom phrase configuration, used to improve the translation accuracy of specific terms.
corpus.phrasesMap<String, Object>No
Custom phrase mapping. The key is a source-language term, and the value is its translation in the target language.
Example:
{"Inteligencia Artificial": "Artificial Intelligence"}
API reference
OmniRealtimeConversation class
OmniRealtimeConversation is introduced via import com.alibaba.dashscope.audio.omni.OmniRealtimeConversation;.
| Method signature | Server response events (delivered via callback) | Description |
|---|---|---|
| None | Constructor. | |
Server eventsSession createdServer events Session configuration updated | Establishes a connection with the server. | |
Server eventsSession configuration updated | Updates the session configuration. We recommend calling this method first after the connection is established. If this method is not called, the system uses the default configuration. Only the parameters involved in OmniRealtimeConfig need to be considered. | |
| None | Appends Base64-encoded audio data chunks to the cloud input audio buffer. The server automatically detects speech start and end and triggers translation. | |
input_audio_buffer.committedInput audio buffer committed | In Manual mode, commits the audio previously appended to the cloud buffer via the appendAudio method. The server automatically starts generating a translation response upon receipt. In VAD mode, this method does not need to be called; the server commits automatically. | |
input_audio_buffer.clearedInput audio buffer cleared | Clears the audio data in the current cloud buffer that has not been committed. | |
session.finishedThe server completes the speech translation and ends the session | Notifies the server to end the session. After receiving the session end notification, the server completes the final speech translation. | |
| None | Terminates the task and closes the connection. | |
| None | Gets the session_id of the current task. | |
| None | Gets the response_id of the most recent response. | |
| None | Gets the first text delay of the most recent response (in milliseconds). | |
| None | Gets the first audio delay of the most recent response (in milliseconds). |
Callback interface (OmniRealtimeCallback)
The server returns server-side response events and data to the client through callbacks.
Extend this class and implement the corresponding methods to handle server events.
Introduced via import com.alibaba.dashscope.audio.omni.OmniRealtimeCallback;.
| Method signature | Parameters | Description |
|---|---|---|
| None | Triggered when the WebSocket connection is successfully established. | |
| message: Server events | Triggered when a server event is received. | |
| code: status codereason: log information when the WebSocket connection is closed | Triggered when the WebSocket connection is closed. |