This document describes how to use the DashScope Java SDK to call the realtime 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.
- Obtain and configure an API Key.
- Learn about realtime speech/audio and video translation - Qwen.
QuickStart
The following example shows how to record audio from a microphone in real time and perform translation.
Microphone realtime translation sample code
Microphone realtime translation sample code
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 sample code
Parameter Type Required Description modelStringYes The name of the model to use. We recommend qwen3.5-livetranslate-flash-realtime.urlStringYes Realtime translation service URL: - 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 sample code
Extended session parameters Some session parameters do not have corresponding SDK configuration methods. You can pass them in throughParameter
Type
Required
Description
modalitiesList<OmniRealtimeModality>No
The model output modalities.
Default value:
[OmniRealtimeModality.AUDIO, OmniRealtimeModality.TEXT].Value range:
[OmniRealtimeModality.TEXT]: Output text only[OmniRealtimeModality.AUDIO, OmniRealtimeModality.TEXT]: Output text and audio
voiceStringYes
The voice of the generated audio.
Default value:
The default voice of Qwen3.5-LiveTranslate-Flash-Realtime is:
Tina
Optional 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
The input audio transcription model. You must set this parameter if you need to output the transcription of the source speech.
Optional value:
qwen3-asr-flash-realtime.translationConfigOmniRealtimeTranslationParamNo
Translation-related configuration.
enableTurnDetectionbooleanNo
Whether to enable VAD (Voice Activity Detection).
Default value:
true, that is, VAD mode is enabled. The server automatically detects the start and end of speech and automatically triggers translation.Set to
falseto switch to Manual mode, where the client manually submits audio through thecommit()method. For detailed parameter descriptions, see turn_detection object (Optional) The Voice Activity Detection (VAD) configuration, used to control how the start and end of speech are detected: Set to a configuration object (default): VAD mode is enabled. The server automatically detects the start and end of speech, automatically commits the audio buffer, and triggers translation responses. The client does not need to send the input_audio_buffer.commit event. Set to null: Manual mode is enabled. The client manually commits the audio buffer through the input_audio_buffer.commit event, and the server automatically starts generating translation responses upon receipt. Properties type string (Optional) The VAD type, fixed as server_vad. threshold float (Optional) The VAD detection sensitivity. A lower value makes it easier to recognize faint sounds (including background noise) as speech; a higher value requires clearer and louder speech to trigger. Value range: [-1.0, 1.0], default value 0.2. silence_duration_ms integer (Optional) The minimum duration of silence (in milliseconds) that must be maintained after speech ends. After this duration, the speech is considered ended, and the server automatically commits the audio buffer and triggers a translation response. Value range: [200, 6000], default value 1000..OmniRealtimeConfig.builder().parameters(Map). The keys in the Map are written directly intosession. For example, to enable real-time voice cloning, first construct the following parameters:In the existing configuration builder chain, set the voice to.voice("default")and add.parameters(parameters). Keep the original language and audio settings, and callconversation.updateSession(config)after building. For the pairing of cloning frequency and voice, see Voice Cloning. -
The following parameters are set through the chained methods of OmniRealtimeTranslationParam.
Click to view sample code
Parameter
Type
Required
Description
languageStringNo
The target language code for translation.
Default value:
en.Optional values: See Supported languages.
corpusOmniRealtimeTranslationParam.CorpusNo
The hotword configuration, used to improve the translation accuracy of specific terms.
corpus.phrasesMap<String, Object>No
The hotword mapping table. The key is a term in the source language, and the value is its corresponding translation in the target language.
Example:
{"artificial intelligence": "Artificial Intelligence"}
API reference
OmniRealtimeConversation class
OmniRealtimeConversation is imported through import com.alibaba.dashscope.audio.omni.OmniRealtimeConversation;.
| Method signature | Server response events (delivered via callbacks) | Description |
|---|---|---|
| None | Constructor. | |
Server eventsSession createdServer events Session configuration updated | Establishes a connection with the server. | |
Server eventsSession configuration updated | Used to update the session configuration. It is recommended to call this method first to apply settings after the connection is established. If this method is not called, the system will use 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 the start and end of speech 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; once the server receives it, it automatically starts generating the translation response. In VAD mode, this method does not need to be called, as the server commits automatically. | |
input_audio_buffer.clearedInput audio buffer cleared | Clears the audio data in the current cloud buffer that has not yet 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 will complete the final speech translation. | |
| None | Terminates the task and closes the connection. | |
| None | Obtains the session_id of the current task. | |
| None | Obtains the response_id of the most recent response. | |
| None | Obtains the first-text latency of the most recent response (in milliseconds). | |
| None | Obtains the first-audio latency of the most recent response (in milliseconds). |
Callback interface (OmniRealtimeCallback)
The server returns server response events and data to the client via callbacks.
Extend this class and implement the corresponding methods to handle server events.
Import it via import com.alibaba.dashscope.audio.omni.OmniRealtimeCallback;.
| Method signature | Parameter | 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 recorded when the WebSocket connection is closed | Triggered when the WebSocket connection is closed. |