Java SDK
The key interfaces and request parameters for Qwen-Omni real-time DashScope Java SDK.
Prerequisites
Your Java SDK version must be v2.22.15 or later. Before you begin, 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 from a microphone, enables Voice Activity Detection (VAD) mode, which automatically detects the start and end of speech, and supports voice interruption.
Set the enableTurnDetection parameter to
true.Use headphones for audio playback to prevent echoes from triggering voice interruption.
-
Audio and video conversation example: Captures real-time audio and video from a microphone and camera, enables VAD mode, and supports voice interruption.
Set the enableTurnDetection parameter to
true.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.
Set the enableTurnDetection parameter to
false.
Request parameters
Configure the following request parameters using the chained methods or setters of the OmniRealtimeParam object, and then pass it to the OmniRealtimeConversation constructor.
|
Parameter |
Type |
Description |
|
model |
String |
The Qwen-Omni model to use. See Model list. |
|
url |
String |
The endpoint URL:
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 using the chained methods or setters of the OmniRealtimeConfig object, and then pass it to the updateSession method.
|
Parameter |
Type |
Description |
|
modalities |
List<OmniRealtimeModality> |
The model output modality. Set to [OmniRealtimeModality.TEXT] for text only, or [OmniRealtimeModality.TEXT, OmniRealtimeModality.AUDIO] for both audio and text. |
|
voice |
String |
The voice for audio output. For supported voices, see Voice list. Default voice:
|
|
inputAudioFormat |
OmniRealtimeAudioFormat |
The format of the user's input audio. Currently only supports |
|
outputAudioFormat |
OmniRealtimeAudioFormat |
The format of the model's output audio. Currently only supports |
|
instructions |
String |
A system message that sets the goal or role for the model. Example: "You are an AI customer service agent for a five-star hotel. Answer customer questions about room types, facilities, prices, and booking policies accurately and in a friendly manner. Always respond professionally and helpfully. Do not provide unverified information or information outside the scope of the hotel's services." Note
Set
|
|
smooth_output |
Boolean |
This parameter is supported only by the Qwen3-Omni-Flash-Realtime series.
Set |
|
enableInputAudioTranscription |
Boolean |
Enables speech recognition for input audio. |
|
InputAudioTranscription |
String |
Speech recognition model for input audio transcription. The value is always qwen3-asr-flash-realtime. This parameter is not configurable. |
|
enableTurnDetection |
Boolean |
Enables VAD. If disabled, you must manually submit audio to create a response. |
|
turnDetectionType |
String |
The VAD type. Valid values:
|
|
turnDetectionThreshold |
Float |
VAD detection threshold. Increase in noisy environments and decrease in quiet environments.
Default: 0.5. Valid values: [-1.0, 1.0]. |
|
turnDetectionSilenceDurationMs |
Integer |
Silence duration that indicates end of speech. If exceeded, the model triggers a response. Default: 800. Valid values: [200, 6000]. |
|
turnDetectionParam |
Map |
Additional Example: |
|
enable_search |
Boolean |
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 and cannot be enabled at the same time. |
|
search_options |
Object |
Web search option settings. This parameter takes effect only after
|
|
tools |
List<Map<String, Object>> |
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 Map 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. Default values of temperature:
|
|
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 values of top_p:
|
|
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 values of top_k:
|
|
max_tokens |
Integer |
Maximum number of tokens to return.
Default and maximum values equal the model's maximum output length. See Model list 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 values of repetition_penalty:
|
|
presence_penalty |
Float |
Controls content repetition in model output. Valid values: [-2.0, 2.0]. Positive values reduce repetition; negative values increase it. Default values of presence_penalty:
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 import com.alibaba.dashscope.audio.omni.OmniRealtimeConversation;.
|
Method signature |
Server response event (sent via callback) |
Description |
|
Session created Session configuration updated |
Creates a connection to 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 session.update event, it validates the parameters. Invalid parameters return an error; otherwise the server updates session configuration. |
|
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:
|
|
The audio received by the server is cleared |
Deletes the audio in the current cloud buffer. |
|
The server received the committed audio |
Commits audio and video from the cloud buffer. Returns an error if the buffer is empty.
Note:
|
|
The server starts to generate a response New output content is available in the response A conversation item is created New output content is 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 is complete Audio generation is complete Streaming of text or audio content for the assistant message is complete Streaming of the entire output item for the assistant message is complete The response is complete |
Instructs the server to create a model response. When the session is configured in "turn_detection" mode, the server automatically creates a model response. |
|
None |
Cancels the in-progress response. If no response is available to cancel, the server returns an error. |
|
None |
Sends the The item parameter is a JsonObject and must contain the following fields:
|
|
None |
Stops 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. |
Callback interface (OmniRealtimeCallback)
The server returns response events and data via callbacks. Implement callback methods to process server responses.
Import with import com.alibaba.dashscope.audio.omni.OmniRealtimeCallback;.
|
Method |
Parameter |
Return value |
Description |
|
|
None |
None |
Called immediately after a connection is established with the server. |
|
message: The server response event. |
None |
Contains interface call responses and model-generated text and audio. See Server events. |
|
code: The status code for closing the WebSocket. reason: The reason for closing the WebSocket. |
None |
Called after the connection to the server is closed. |
FAQ
Q: How are the input audio and images aligned?
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 that you send images at a frame rate of 1 or 2 fps and send 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.