CosyVoice voice cloning Python SDK reference (VoiceEnrollmentService).
CosyVoice voice cloning can be called via the DashScope Python SDK using the
Set the base URL before creating the service:
Package:
Create a cloned voice from audio.
Returns:
List cloned voices with optional filtering and pagination.
Returns:
Query details of a specific cloned voice.
Returns:
Update a cloned voice with new audio.
Returns:
Delete a cloned voice.
Returns:
VoiceEnrollmentService class. This SDK covers voice cloning only — CosyVoice voice design and all Qwen voice cloning/design must use the HTTP API.
User guide: Voice cloning.
Prerequisites
- An API key configured as the
DASHSCOPE_API_KEYenvironment variable - The latest DashScope SDK
Service URL
Set the base URL before creating the service:
VoiceEnrollmentService class
Package: dashscope.audio.tts_v2.VoiceEnrollmentService
Manages the lifecycle of CosyVoice cloned voices (create, list, query, update, delete).
Constructor
create_voice()
Create a cloned voice from audio.
| Parameter | Type | Required | Description |
|---|---|---|---|
| target_model | str | Yes | Speech synthesis model for the cloned voice. Must match the model in your synthesis calls. |
| prefix | str | Yes | Voice name prefix. Alphanumeric only, max 10 characters. Generated name format: {target_model}-{prefix}-{unique_id}. |
| url | str | Yes | Audio file URL for cloning. Must be publicly accessible. |
| language_hints | List[str] | No | Language hint for the audio. Only the first element is used. Default: ["zh"]. |
| max_prompt_audio_length | float | No | Max audio duration (seconds) after preprocessing. Range: [3.0, 30.0]. Default: 10.0. |
| enable_preprocess | bool | No | Enable audio preprocessing (noise reduction, enhancement). Default: False. |
str — the generated voice ID (voice_id).
list_voice()
List cloned voices with optional filtering and pagination.
| Parameter | Type | Required | Description |
|---|---|---|---|
| prefix | str | No | Filter voices by name prefix. |
| page_index | int | No | Page number, starting from 0. Default: 0. |
| page_size | int | No | Results per page. Default: 10. |
list — list of voice objects.
query_voice()
Query details of a specific cloned voice.
| Parameter | Type | Required | Description |
|---|---|---|---|
| voice_id | str | Yes | The voice ID to query. |
dict — voice details including status, resource_link, target_model, etc.
update_voice()
Update a cloned voice with new audio.
| Parameter | Type | Required | Description |
|---|---|---|---|
| voice_id | str | Yes | The voice ID to update. |
| url | str | Yes | New audio file URL. Must be publicly accessible. |
| language_hints | List[str] | No | Language hint for the new audio. |
| max_prompt_audio_length | float | No | Max audio duration (seconds) after preprocessing. |
| enable_preprocess | bool | No | Enable audio preprocessing. |
None
delete_voice()
Delete a cloned voice.
| Parameter | Type | Required | Description |
|---|---|---|---|
| voice_id | str | Yes | The voice ID to delete. |
None