Clone and manage Qwen-Audio and CosyVoice voices with the DashScope Python SDK.
Service endpoint
The SDK service endpoint is determined by the workspace/region parameters of the Client constructor (corresponding to the addresses below, which include the WorkspaceId). To switch to a different region, change the Client constructor parameters to the values for that region.
- API keys differ by region. Use the API key for the target region.
- The region setting is a
Client-level setting and affects all DashScope SDK API calls made by thatClient.
- China (Beijing)
- Singapore
https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/api/v1Replace {WorkspaceId} with your actual workspace ID.Core resource (client.audio.voices)
Purpose: Manage the lifecycle of Qwen-Audio-TTS, Qwen-Audio-Realtime, and CosyVoice cloned voices (create, query, update, and delete).
Client construction (authentication and region)
create() — Create a voice
Method signature:
| Parameter | Type | Required | Description |
|---|---|---|---|
| target_model | str | Yes | The target model that uses the voice. It must match the model used in subsequent requests with this voice; otherwise, the requests fail. |
| prefix | str | Yes | A prefix for the voice name. Only alphanumeric characters are allowed, with a maximum length of 10 characters. The resulting voice name follows this format: {target_model}-{prefix}-{unique_id}. |
| url | str | Yes | Reference audio for voice cloning. Accepts a publicly accessible URL or a Base64 Data URI, such as data:audio/wav;base64,.... |
| language_hints | List[str] | No | Helps the model identify the language of the sample audio to extract voice features more accurately and improve cloning quality. If the specified language doesn't match the actual audio language (for example, setting en when the audio is in Chinese), the system ignores this value and detects the language automatically.This parameter is an array and must contain exactly one element.Applies to qwen-audio-3.1-tts-plus, qwen-audio-3.1-tts-flash, qwen-audio-3.0-tts-plus, qwen-audio-3.0-tts-flash, qwen-audio-3.1-realtime-plus, qwen-audio-3.1-realtime-flash, qwen-audio-3.0-realtime-plus, qwen-audio-3.0-realtime-flash, cosyvoice-v3.5-plus, cosyvoice-v3.5-flash, cosyvoice-v3-plus, cosyvoice-v3-flash.
Click to view supported languages by model
|
| max_prompt_audio_length | float | No | The maximum duration (in seconds) of the reference audio used for voice cloning after preprocessing. Valid values: [3.0, 30.0].Default: 10.0. Applies to qwen-audio-3.1-tts-plus, qwen-audio-3.1-tts-flash, qwen-audio-3.0-tts-plus, qwen-audio-3.0-tts-flash, qwen-audio-3.1-realtime-plus, qwen-audio-3.1-realtime-flash, qwen-audio-3.0-realtime-plus, qwen-audio-3.0-realtime-flash, cosyvoice-v3.5-plus, cosyvoice-v3.5-flash, cosyvoice-v3-flash. |
| enable_preprocess | bool | No | Whether to enable audio preprocessing (noise reduction, audio enhancement, and volume normalization). Enable this for recordings with background noise. Disable it for recordings in quiet environments to preserve the original voice characteristics.Default: false. Applies to qwen-audio-3.1-tts-plus, qwen-audio-3.1-tts-flash, qwen-audio-3.0-tts-plus, qwen-audio-3.0-tts-flash, qwen-audio-3.1-realtime-plus, qwen-audio-3.1-realtime-flash, qwen-audio-3.0-realtime-plus, qwen-audio-3.0-realtime-flash, cosyvoice-v3.5-plus, cosyvoice-v3.5-flash, cosyvoice-v3-flash. |
| enable_volume_normalization | bool | No | Specifies whether to normalize the volume of the sample audio used for voice cloning. Pass this parameter through the extra_input dictionary. Default value: False. If you set this parameter to True, the volume of audio synthesized with the created voice may differ from that of audio synthesized with a voice created with this parameter disabled. |
Voice object, whose voice_id is the voice ID and whose request_id is the request ID.
list() — List voices
Method signature:
| Parameter | Type | Required | Description |
|---|---|---|---|
| prefix | str | No | Filter by voice name prefix. |
| page_index | int | No | Page index. Default: 0. |
| page_size | int | No | Number of entries per page. Default: 10. |
VoiceList object, whose voices is the list of voices and whose request_id is the request ID. Each list item is a dictionary. Use voice.get("target_model") to get the target model ID.
get() — Query voice details
Method signature:
| Parameter | Type | Required | Description |
|---|---|---|---|
| voice_id | str | Yes | The voice ID to query. |
Voice object containing the voice details. Use voice.target_model to get the target model ID.
update() — Update a voice
Method signature:
| Parameter | Type | Required | Description |
|---|---|---|---|
| voice_id | str | Yes | The voice ID to update. |
| url | str | Yes | New reference audio. Accepts a publicly accessible URL or a Base64 Data URI, such as data:audio/wav;base64,.... |
delete() — Delete a voice
Method signature:
| Parameter | Type | Required | Description |
|---|---|---|---|
| voice_id | str | Yes | The voice ID to delete. |
Code examples
Create a voice
url assignment above with the following code before calling client.audio.voices.create(). To update a voice, also pass the Data URI through the url parameter of client.audio.voices.update(). Replace sample.wav with your local audio path.