Qwen-Audio-TTS/CosyVoice voice cloning is accessible through the DashScope Python SDK.
Service endpoint
The SDK uses the China (Beijing) region endpoint by default. To switch to a different region, set dashscope.base_http_api_url before you initialize the client.
- Singapore
- China (Beijing)
https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1Replace {WorkspaceId} with your actual workspace ID.Note :
API keys differ between regions. Use the API key that corresponds to the target region.
The region setting is global and affects all DashScope SDK API calls.
VoiceEnrollmentService class
Package path: dashscope.audio.tts_v2.VoiceEnrollmentService
Purpose: Manage the lifecycle of Qwen-Audio-TTS/CosyVoice cloned voices, including creating, querying, updating, and deleting voices.
Constructor
create_voice() — Create a voice
Method signature:
Parameter | Type | Required | Description |
|---|---|---|---|
target_model | str | Yes | The text-to-speech (TTS) model that drives the cloned voice. It must match the model you specify when calling the TTS API; otherwise, synthesis fails. |
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: |
url | str | Yes | The URL of the audio file for voice cloning. The URL must be publicly accessible. |
language_hints | List[str] | No | Applies only to Qwen-Audio-TTS/CosyVoice voice cloning (when model is 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 This parameter is an array, but the current version processes only the first element. Valid values vary by model:
Default: ["zh"]. |
max_prompt_audio_length | float | No | Applies only to Qwen-Audio-TTS/CosyVoice voice cloning (when model is The maximum duration (in seconds) of the reference audio after preprocessing. Valid values: [3.0, 30.0]. Default: 10.0. |
enable_preprocess | bool | No | Applies only to Qwen-Audio-TTS/CosyVoice voice cloning (when model is 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. |
enable_volume_normalization | bool | No | Specifies whether to normalize the volume of the sample audio used for voice cloning. Pass this parameter directly as a keyword argument. Default value: |
str — The voice ID (voice_id).
list_voices() — 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. |
list — A list of voices.
query_voice() — Query voice details
Method signature:
Parameter | Type | Required | Description |
|---|---|---|---|
voice_id | str | Yes | The voice ID to query. |
dict — Voice details.
update_voice() — Update a voice
Method signature:
Parameter | Type | Required | Description |
|---|---|---|---|
voice_id | str | Yes | The voice ID to update. |
url | str | Yes | The new audio file URL. |
language_hints | List[str] | No | Language hints for the sample audio. |
max_prompt_audio_length | float | No | Maximum duration of the reference audio. |
enable_preprocess | bool | No | Whether to enable audio preprocessing. |
delete_voice() — Delete a voice
Method signature:
Parameter | Type | Required | Description |
|---|---|---|---|
voice_id | str | Yes | The voice ID to delete. |