This document describes the key interfaces and request parameters for calling Qwen-TTS-Realtime models with the DashScope Java SDK.
Prerequisites
The DashScope Java SDK version must be 2.22.7 or later.
QuickStart
Request parameters
The following request parameters can be configured through the chained methods or setters of the QwenTtsRealtimeParam object, and then passed as a parameter to the constructor of QwenTtsRealtime to complete the configuration.
Parameter | Type | Required | Description |
|---|---|---|---|
model | String | Yes | Model name. Seesupported models。 |
url | String | Yes | China (Beijing) region: Singapore region: |
QwenTtsRealtimeConfig object, and then passed as a parameter to the updateSession API to complete the configuration.
Parameter | Type | Required | Description |
|---|---|---|---|
voice | String | Yes | The voice used for speech synthesis. SeeQwen-TTS voice list。 |
languageType | String | No | The language of the synthesized audio. The default is
|
mode | String | No | Interaction mode. Valid values:
|
format | String | No | The format of the audio output by the model. Supported formats:
|
sampleRate | int | No | The sample rate (Hz) of the audio output by the model. Supported sample rates:
|
speechRate | float | No | The speech rate of the audio. 1.0 is the normal rate, less than 1.0 is slower, and greater than 1.0 is faster. Default value: 1.0. Value range: [0.5, 2.0]. |
volume | int | No | The volume of the audio. Value range: [0, 100]. |
pitchRate | float | No | The pitch of the synthesized audio. Default value: 1.0. Value range: [0.5, 2.0]. |
bitRate | int | No | Specifies the audio'sbit rate(kbps). A higher bit rate delivers better audio quality but a larger audio file. This parameter is available only when the audio format ( Default value: 128. Value range: [6, 510]. |
API reference
QwenTtsRealtime class
Import method:
| Member methods | Method signature | Server response events (delivered via callbacks) | Description |
|---|---|---|---|
| connect | session.createdThe session has been createdsession.updated The session configuration has been updated | Creates a connection to the server. | |
| updateSession | session.updatedThe session configuration has been updated | Updates the default configuration for interactions in this session. For parameter configuration, see the "Request parameters" section.After you establish a connection, the server promptly returns the default input and output configuration for this session. If you need to update the default session configuration, we recommend that you always call this API immediately after establishing the connection.After receiving the session.update event, the server validates the parameters. If any parameter is invalid, an error is returned; otherwise, the server-side session configuration is updated. | |
| appendText | None | Appends a text fragment to the cloud-side input text buffer. The buffer is a temporary store that you can write to and commit later.
| |
| clearAppendedText | input_text_buffer.clearedClear the text received on the server | Deletes the text in the current cloud buffer. | |
| commit | input_text_buffer.committedSubmit text and trigger speech synthesisresponse.output_item.added New output content in the responseresponse.content_part.added New output content added to the assistant message itemresponse.audio.deltaAudio incrementally generated by the modelresponse.audio.doneAudio generation completedresponse.content_part.doneThe audio content of the assistant message has finished streaming outputresponse.output_item.doneAll output items of the assistant message have finished streamingresponse.doneResponse completed | Submits the text previously appended to the cloud buffer via append, and immediately synthesizes all the text. If the input text buffer is empty, an error will occur.
| |
| finish | session.finishedResponse completed | Terminates the task. | |
| close | None | Closes the connection. | |
| getSessionId | None | Obtains the session_id of the current task. | |
| getResponseId | None | Obtains the response_id of the most recent response. | |
| getFirstAudioDelay | None | Obtains the first audio packet latency. |
Callback interface (QwenTtsRealtimeCallback)
| Method | Parameter | Return value | Description |
|---|---|---|---|
| None | None | This method is called back immediately after the connection to the server is established. | |
| message: the server response event. | None | Includes responses to API calls and text and audio generated by the model. For details, see: Server events | |
| code: the status code of the WebSocket closure.reason: the close reason of the WebSocket. | None | Called back after the server has closed the connection. |