This topic describes how to use the server-side Python software development kit (SDK) for real-time multimodal interaction with Alibaba Cloud Model Studio. It covers how to download and install the SDK, its key APIs, and provides code examples.
Real-time multimodal interaction service architecture

Prerequisites
You must activate the service and obtain the required parameters.
Enable an Alibaba Cloud Model Studio real-time multimodal interaction application to get your workspace ID, app ID, and API key.
Audio format specifications
The server-side connection type only supports the WebSocket protocol.
-
Audio format for WebSocket connections:
- Uplink: Supports Pulse-Code Modulation (PCM) (16 kHz sample rate, 16-bit, single-channel) and Opus audio streams.
- Downlink: Supports PCM and MP3 audio streams.
Environment dependencies
Runtime environment: Python 3.9 or later.
Installing dependencies:
Install the Dashscope dependency using pip. Version 1.24.2 or later is required.
API reference
dashscope.multimodal.MultiModalDialog
Service endpoint
Method description:
1. MultiModalDialog
Creates an interaction and sets a callback.
2. start
Starts the voice_chat dialog service and triggers the on_started callback. The callback returns the dialog_id.
3. start_speech
Notifies the server to start uploading audio. This method can only be called when the dialog state is LISTENING.
4. send_audio_data
Sends audio data to the server.
5. stop_speech
Notifies the server to stop uploading audio.
6. interrupt
Notifies the server that the client needs to interrupt the current interaction and start speaking.
7. local_responding_started
Notifies the server that the client has started playing the text-to-speech (TTS) audio.
8. local_responding_ended
Notifies the server that the client has finished playing the TTS audio.
9. stop
Ends the current round of the voice_chat dialog.
10. get_dialog_state
Retrieves the current state of the dialog service. The state is returned as a DialogState enumeration.
11. request_to_respond
Requests the server to directly synthesize speech from text, or sends an instruction to the server.
12. classMultiModalCallback
Callback function
Dialog states (DialogState)
The multimodal dialog service has three states: LISTENING, THINKING, and RESPONDING.
- LISTENING (str): The bot is listening for user input. During this state, you can send audio.
- THINKING (str): The bot is thinking.
- RESPONDING (str): The bot is generating or playing back a spoken response.
Usage notes
Parameter settings
You can set parameters for multimodal interaction using the RequestParameters class. This class includes multiple parameter segments, such as up_stream, down_stream, and client_info. The following table provides more details.
Level-1 parameter | Level-2 parameter | Level-3 parameter | Level-4 parameter | Type | Required | Description |
task_group | The name of the task group. Set to "aigc". | |||||
task | The name of the task. Set to "multimodal-generation". | |||||
function | The feature to call. Set to "generation". | |||||
model | The service name. Set to "multimodal-dialog". | |||||
input | workspace_id | string | Yes | The user's workspace ID. | ||
app_id | string | Yes | The ID of the application created by the customer in the console. This ID determines which dialog system to use. | |||
sandbox | boolean | No | Specifies whether to use the test configuration. Default is false. | |||
directive | string | Yes | The instruction name: Start. | |||
dialog_id | string | No | The dialog ID. If provided, the conversation continues. | |||
parameters | upstream | type | string | Yes | Uplink type:
| |
mode | string | No | The mode used by the client. Options:
Default is tap2talk. | |||
audio_format | string | No | The audio format. Supports pcm and opus. Default is pcm. | |||
downstream | voice | string | No | The voice for speech synthesis. | ||
sample_rate | int | No | The sample rate for speech synthesis. Default is 24000 Hz. | |||
intermediate_text | string | No | Controls which intermediate text is returned to the user:
You can set multiple types, separated by commas. Default is transcript. | |||
debug | boolean | No | Specifies whether to send debug information. Default is false. | |||
audio_format | string | No | The audio format. Supports pcm and mp3. Default is pcm. | |||
client_info | user_id | string | Yes | The end user ID, used for user-related processing. | ||
device | uuid | string | No | A globally unique ID for the client. You must generate this ID and pass it to the SDK. | ||
network | ip | string | No | The public IP address of the caller. | ||
location | latitude | string | No | The latitude information of the caller. | ||
longitude | string | No | The longitude information of the caller. | |||
city_name | string | No | The city where the caller is located. | |||
biz_params | user_defined_params | object | No | Other parameters to pass through to the agent. | ||
user_defined_tokens | object | No | Pass-through authentication information required by the agent. | |||
tool_prompts | object | No | Pass-through prompt required by the agent. | |||
user_query_params | object | No | Pass-through custom parameters for the user request. | |||
user_prompt_params | object | No | Pass-through custom parameters for the user prompt. |
Example
Call interaction sequence diagram

More SDK interface usage instructions
VQA (Visual Q&A) interaction
Visual Q&A (VQA) is a feature that enables multimodal interaction by combining images and voice. This is accomplished by sending images during a conversation.
To trigger VQA, you can either provide voice input with an intent, such as "take a look at xxx", or enter a text request directly. The system then returns a Q&A result based on the image content.
-
To make a request using voice:
- The voice prompt is "See what's ahead."
- The callback function
on_responding_contentreturns the photo-taking intent "visual_qa". - After the client receives this intent, it calls the
request_to_respondmethod to submit the image content and trigger a Q&A response.
-
To make a request directly using text:
- The client directly calls the
request_to_respondmethod to submit the image content and a text query, which triggers a Q&A response.
- The client directly calls the
Requesting LiveAI (video call) over WebSocket
LiveAI (video call) is an official agent from Model Studio for multimodal interaction. You can implement the video call feature by sending an image sequence through the Python SDK. To do this, use Real-Time Communication (RTC) on your server and client (web or app) to transmit video and audio. Then, send the video frames captured by the server to the SDK at a rate of one frame every 500 ms, while simultaneously providing real-time audio input.
Note: LiveAI only supports sending Base64-encoded images. The size of each image must be less than 180 KB.
- LiveAI call sequence

- Key code example
Text-to-speech (TTS) synthesis
The SDK lets you directly request the server to synthesize audio from text.
You can send the request_to_respond request when the client is in the Listening state.
If the current state is not Listening, you must first call the interrupt method to stop the current playback.
Custom prompt variables and value passing
- You can configure custom variables in the Prompts section of the project console.
user_name field is defined for the user's nickname. The variable user_name is then used in the prompt as the placeholder ${user_name}.

- You can set the variable in your code.
user_name to Dami.
- Example response

Requesting dialog results using text
The SDK lets you send a text input and directly request the server to return Large Language Model (LLM) results and speech synthesis data.
You can send the request_to_respond request when the client is in the Listening state.