This topic describes the key interfaces and request parameters for calling Qwen-TTS-Realtime models with the DashScope Java SDK.
Prerequisites
Requires DashScope Java SDK 2.22.7 or later.
Quick start
Request parameters
Configure the following request parameters with the chaining methods or setters of a QwenTtsRealtimeParam object, then pass the object to the QwenTtsRealtime constructor.
Parameter | Type | Required | Description |
|---|---|---|---|
model | String | Yes | Model name (see Supported models). |
url | String | Yes | China (Beijing): Singapore: |
QwenTtsRealtimeConfig object, then pass the object to the updateSession method.
Parameter | Type | Required | Description |
|---|---|---|---|
voice | String | Yes | The voice for speech synthesis. For more information, see Qwen-TTS voice list. |
languageType | String | No | Specifies the language of the synthesized audio. The default value is
|
mode | String | No | The interaction mode. Valid values:
|
format | String | No | The format of the audio output from the model. Supported formats:
|
sampleRate | int | No | The sample rate of the audio output from the model, in Hz. Supported sample rates:
|
speechRate | float | No | The speech rate of the audio. A value of 1.0 is the normal speed, a value less than 1.0 is slower, and a value greater than 1.0 is faster. Default value: 1.0. Valid range: [0.5, 2.0]. |
volume | int | No | The volume of the audio. Valid range: [0, 100]. |
pitchRate | float | No | The pitch of the synthesized audio. Default value: 1.0. Valid range: [0.5, 2.0]. |
bitRate | int | No | Specifies the bitrate of the audio in kbps. A higher bitrate results in better audio quality and a larger audio file. This parameter is available only when the audio format ( Default value: 128. Valid range: [6, 510]. |
API reference
QwenTtsRealtime class
To import:
| Method | Signature | Server events | Description |
|---|---|---|---|
| connect | session.createdSession createdsession.updated Session configuration updated | Creates a connection with the server. | |
| updateSession | session.updatedSession configuration updated | Updates the session configuration. See Request parameters.After connecting, the server returns default input and output configurations for the session. Call this method immediately after connect() to override defaults.The server validates parameters upon receiving a session.update event. If any parameter is invalid, the server returns an error. Otherwise, it updates the session configuration on the server side. | |
| appendText | None | Appends a text segment to the server-side input buffer. The buffer stores text until you submit it.
| |
| clearAppendedText | input_text_buffer.clearedClears text received by the server | Clears all text in the server-side input buffer. | |
| commit | input_text_buffer.committedCommits text and triggers speech synthesisresponse.output_item.added New output content appears in the responseresponse.content_part.added New output content added to the assistant message itemresponse.audio.delta Model generates audio incrementallyresponse.audio.done Audio generation completedresponse.content_part.done Streaming of audio content for the assistant message is completeresponse.output_item.done Streaming of the entire output item for the assistant message is completeresponse.done Response completed | Commits text previously appended to the server-side buffer and synthesizes all text immediately. Returns an error if the buffer is empty.
| |
| finish | session.finishedResponse completed | Stops the current task. | |
| close | None | Closes the connection. | |
| getSessionId | None | Returns the session ID of the current task. | |
| getResponseId | None | Returns the response ID of the most recent response. | |
| getFirstAudioDelay | None | Returns the latency of the first audio packet in milliseconds. |
Callback interface (QwenTtsRealtimeCallback)
| Method | Parameters | Return value | Description |
|---|---|---|---|
| None | None | Called immediately after the WebSocket connection is established. | |
| message: server-side response event. | None | Called when the server sends an event, including responses to API calls and model-generated text and audio. See Server-side events. | |
| code: WebSocket close status code.reason: Close reason. | None | Called after the server closes the connection. |