Skip to main content
CosyVoice SDK

Java SDK

CosyVoice voice cloning Java SDK reference (VoiceEnrollmentService).

CosyVoice voice cloning can be called via the DashScope Java SDK using the VoiceEnrollmentService class. This SDK covers voice cloning only — CosyVoice voice design and all Qwen voice cloning/design must use the HTTP API.

Prerequisites

Service URL

Set the base URL before creating the service:
import com.alibaba.dashscope.common.Constants;

Constants.baseHttpApiUrl = "https://dashscope-intl.aliyuncs.com/api/v1";

VoiceEnrollmentService class

Package: com.alibaba.dashscope.audio.ttsv2.enrollment.VoiceEnrollmentService Manages the lifecycle of CosyVoice cloned voices (create, list, query, update, delete).

Constructor

public VoiceEnrollmentService(String apiKey)
ParameterTypeDescription
apiKeyStringYour DashScope API key.

createVoice()

Create a cloned voice from audio.
public Voice createVoice(String targetModel, String prefix, String url,
                         VoiceEnrollmentParam customParam)
    throws NoApiKeyException, InputRequiredException
ParameterTypeRequiredDescription
targetModelStringYesSpeech synthesis model for the cloned voice. Must match the model in your synthesis calls.
prefixStringYesVoice name prefix. Alphanumeric only, max 10 characters.
urlStringYesAudio file URL for cloning. Must be publicly accessible.
customParamVoiceEnrollmentParamNoOptional parameters (languageHints, maxPromptAudioLength, etc.). See VoiceEnrollmentParam.
Returns: Voice object. Call getVoiceId() to get the voice ID.

listVoice()

List cloned voices with optional filtering and pagination.
public Voice[] listVoice(String prefix, int pageIndex, int pageSize)
    throws NoApiKeyException, InputRequiredException
ParameterTypeRequiredDescription
prefixStringNoFilter voices by name prefix.
pageIndexintNoPage number, starting from 0.
pageSizeintNoResults per page.
Returns: Voice[] — array of voice objects.

queryVoice()

Query details of a specific cloned voice.
public Voice queryVoice(String voiceId)
    throws NoApiKeyException, InputRequiredException
ParameterTypeRequiredDescription
voiceIdStringYesThe voice ID to query.
Returns: Voice object with status, target model, and other details.

updateVoice()

Update a cloned voice with new audio.
public void updateVoice(String voiceId, String url, VoiceEnrollmentParam customParam)
    throws NoApiKeyException, InputRequiredException
ParameterTypeRequiredDescription
voiceIdStringYesThe voice ID to update.
urlStringYesNew audio file URL. Must be publicly accessible.
customParamVoiceEnrollmentParamNoOptional parameters.

deleteVoice()

Delete a cloned voice.
public void deleteVoice(String voiceId)
    throws NoApiKeyException, InputRequiredException
ParameterTypeRequiredDescription
voiceIdStringYesThe 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 methodTypeDescription
languageHints(List<String>)List<String>Language hint for the audio. Only the first element is used. Default: ["zh"].
maxPromptAudioLength(Float)FloatMax audio duration (seconds) after preprocessing. Range: [3.0, 30.0]. Default: 10.0.
parameter(String, Object)ObjectSet additional parameters, e.g. parameter("enable_preprocess", false).

enable_preprocess

ParameterTypeRequiredDescription
enable_preprocessbooleanNoEnable audio preprocessing (noise reduction, enhancement, volume normalization). Recommended for noisy audio; disable for clean audio. Default: false.