CosyVoice voice cloning Java SDK reference (VoiceEnrollmentService).
CosyVoice voice cloning can be called via the DashScope Java 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.
Delete a cloned voice.
Package:
VoiceEnrollmentService class. This SDK covers voice cloning only — CosyVoice voice design and all Qwen voice cloning/design must use the HTTP API.
Prerequisites
- An API key
- The latest DashScope SDK
Service URL
Set the base URL before creating the service:
VoiceEnrollmentService class
Package: com.alibaba.dashscope.audio.ttsv2.enrollment.VoiceEnrollmentService
Manages the lifecycle of CosyVoice cloned voices (create, list, query, update, delete).
Constructor
| Parameter | Type | Description |
|---|---|---|
| apiKey | String | Your DashScope API key. |
createVoice()
Create a cloned voice from audio.
| Parameter | Type | Required | Description |
|---|---|---|---|
| targetModel | String | Yes | Speech synthesis model for the cloned voice. Must match the model in your synthesis calls. |
| prefix | String | Yes | Voice name prefix. Alphanumeric only, max 10 characters. |
| url | String | Yes | Audio file URL for cloning. Must be publicly accessible. |
| customParam | VoiceEnrollmentParam | No | Optional parameters (languageHints, maxPromptAudioLength, etc.). See VoiceEnrollmentParam. |
Voice object. Call getVoiceId() to get the voice ID.
listVoice()
List cloned voices with optional filtering and pagination.
| Parameter | Type | Required | Description |
|---|---|---|---|
| prefix | String | No | Filter voices by name prefix. |
| pageIndex | int | No | Page number, starting from 0. |
| pageSize | int | No | Results per page. |
Voice[] — array of voice objects.
queryVoice()
Query details of a specific cloned voice.
| Parameter | Type | Required | Description |
|---|---|---|---|
| voiceId | String | Yes | The voice ID to query. |
Voice object with status, target model, and other details.
updateVoice()
Update a cloned voice with new audio.
| Parameter | Type | Required | Description |
|---|---|---|---|
| voiceId | String | Yes | The voice ID to update. |
| url | String | Yes | New audio file URL. Must be publicly accessible. |
| customParam | VoiceEnrollmentParam | No | Optional parameters. |
deleteVoice()
Delete a cloned voice.
| Parameter | Type | Required | Description |
|---|---|---|---|
| voiceId | String | Yes | The voice ID to delete. |
VoiceEnrollmentParam class
Package: com.alibaba.dashscope.audio.ttsv2.enrollment.VoiceEnrollmentParam
Use the Builder pattern to construct optional parameters for createVoice() and updateVoice().
| Builder method | Type | Description |
|---|---|---|
| languageHints(List<String>) | List<String> | Language hint for the audio. Only the first element is used. Default: ["zh"]. |
| maxPromptAudioLength(Float) | Float | Max audio duration (seconds) after preprocessing. Range: [3.0, 30.0]. Default: 10.0. |
| parameter(String, Object) | Object | Set additional parameters, e.g. parameter("enable_preprocess", false). |
enable_preprocess
| Parameter | Type | Required | Description |
|---|---|---|---|
| enable_preprocess | boolean | No | Enable audio preprocessing (noise reduction, enhancement, volume normalization). Recommended for noisy audio; disable for clean audio. Default: false. |