The SDK uses the China (Beijing) endpoint by default. To switch to a different region, modify Constants.baseHttpApiUrl before initialization.
Singapore
China (Beijing)
https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1Replace {WorkspaceId} with your actual workspace ID.
https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/api/v1Replace {WorkspaceId} with your actual workspace ID.
Switch to the Singapore region:
Copy
import com.alibaba.dashscope.utils.Constants;// Set at the beginning of your codeConstants.baseHttpApiUrl = "https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1";
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.
Alibaba Cloud Model Studio has released workspace-specific domains for the China (Beijing) and Singapore regions. The new dedicated domains deliver superior performance and higher stability for inference requests. We recommend migrating to the new domains:
China (Beijing): from dashscope.aliyuncs.com to {WorkspaceId}.cn-beijing.maas.aliyuncs.com
Singapore: from dashscope-intl.aliyuncs.com to {WorkspaceId}.ap-southeast-1.maas.aliyuncs.com
Replace {WorkspaceId} with your actual Workspace ID. The existing domains remain fully functional.
Package: com.alibaba.dashscope.audio.ttsv2.enrollment.VoiceEnrollmentServicePurpose: Manages the lifecycle of Qwen-Audio-TTS/CosyVoice cloned voices (create, list, retrieve, update, and delete).
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
String
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
String
Yes
The URL of the audio file for voice cloning. The URL must be publicly accessible.
Package: com.alibaba.dashscope.audio.ttsv2.enrollment.VoiceEnrollmentParamBuild parameter objects using the builder pattern.
Method
Type
Description
model(String)
String
The voice cloning model. The value must be "voice-enrollment".
languageHints(List<String>)
List<String>
Applies only to Qwen-Audio-TTS/CosyVoice voice cloning (when model is voice-enrollment). Supported only by qwen-audio-3.0-tts-plus,qwen-audio-3.0-tts-flash, cosyvoice-v3.5-plus, v3.5-flash, v3-plus, and v3-flash.
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, but the current version processes only the first element.
Applies only to Qwen-Audio-TTS/CosyVoice voice cloning (when model is voice-enrollment). Supported only by qwen-audio-3.0-tts-plus,qwen-audio-3.0-tts-flash, cosyvoice-v3.5-plus, v3.5-flash, and v3-flash.
The maximum duration (in seconds) of the reference audio after preprocessing. Valid values: [3.0, 30.0].
Default: 10.0.
parameter(String, Object)
Object
Sets custom parameters, such as parameter("language_hints", Arrays.asList("en")), parameter("max_prompt_audio_length", 10.0f), parameter("enable_preprocess", false), and parameter("enable_volume_normalization", "false").
Applies only to Qwen-Audio-TTS/CosyVoice voice cloning (when model is voice-enrollment). Supported only by qwen-audio-3.0-tts-plus,qwen-audio-3.0-tts-flash, cosyvoice-v3.5-plus, v3.5-flash, and v3-flash.
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
String
No
Whether to normalize the volume of the sample audio used for voice cloning. Valid values are "true" and "false". When enabled, audio synthesized with the created voice may have a different volume than audio synthesized with a voice created with this parameter disabled. Default: "false".
This example requires the third-party library com.google.gson.Gson.
Copy
import com.alibaba.dashscope.audio.ttsv2.enrollment.Voice;import com.alibaba.dashscope.audio.ttsv2.enrollment.VoiceEnrollmentService;import com.alibaba.dashscope.exception.InputRequiredException;import com.alibaba.dashscope.exception.NoApiKeyException;import com.alibaba.dashscope.utils.Constants;import com.google.gson.Gson;import org.slf4j.Logger;import org.slf4j.LoggerFactory;public class Main { public static String apiKey = System.getenv("DASHSCOPE_API_KEY"); // Replace with your API key if not using an environment variable private static String prefix = "myvoice"; // Replace with your actual value private static final Logger logger = LoggerFactory.getLogger(Main.class); public static void main(String[] args) throws NoApiKeyException, InputRequiredException { // The following uses the Singapore region. Replace {WorkspaceId} with your actual workspace ID. For other regions, modify the URL accordingly. Constants.baseHttpApiUrl = "https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1"; VoiceEnrollmentService service = new VoiceEnrollmentService(apiKey); // List voices Voice[] voices = service.listVoice(prefix, 0, 10); logger.info("List successful. Request ID: {}", service.getLastRequestId()); logger.info("Voices Details: {}", new Gson().toJson(voices)); }}
This example requires the third-party library com.google.gson.Gson.
Copy
import com.alibaba.dashscope.audio.ttsv2.enrollment.Voice;import com.alibaba.dashscope.audio.ttsv2.enrollment.VoiceEnrollmentService;import com.alibaba.dashscope.exception.InputRequiredException;import com.alibaba.dashscope.exception.NoApiKeyException;import com.alibaba.dashscope.utils.Constants;import com.google.gson.Gson;import org.slf4j.Logger;import org.slf4j.LoggerFactory;public class Main { public static String apiKey = System.getenv("DASHSCOPE_API_KEY"); // Replace with your API key if not using an environment variable private static String voiceId = "qwen-audio-3.0-tts-flash-myvoice-xxx"; // Replace with your actual value private static final Logger logger = LoggerFactory.getLogger(Main.class); public static void main(String[] args) throws NoApiKeyException, InputRequiredException { // The following uses the Singapore region. Replace {WorkspaceId} with your actual workspace ID. For other regions, modify the URL accordingly. Constants.baseHttpApiUrl = "https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1"; VoiceEnrollmentService service = new VoiceEnrollmentService(apiKey); Voice voice = service.queryVoice(voiceId); logger.info("Query successful. Request ID: {}", service.getLastRequestId()); logger.info("Voice Details: {}", new Gson().toJson(voice)); }}
import com.alibaba.dashscope.audio.ttsv2.enrollment.VoiceEnrollmentService;import com.alibaba.dashscope.exception.InputRequiredException;import com.alibaba.dashscope.exception.NoApiKeyException;import com.alibaba.dashscope.utils.Constants;import org.slf4j.Logger;import org.slf4j.LoggerFactory;public class Main { public static String apiKey = System.getenv("DASHSCOPE_API_KEY"); // Replace with your API key if not using an environment variable private static String fileUrl = "https://your-audio-file-url"; // Replace with your actual value private static String voiceId = "qwen-audio-3.0-tts-flash-myvoice-xxx"; // Replace with your actual value private static final Logger logger = LoggerFactory.getLogger(Main.class); public static void main(String[] args) throws NoApiKeyException, InputRequiredException { // The following uses the Singapore region. Replace {WorkspaceId} with your actual workspace ID. For other regions, modify the URL accordingly. Constants.baseHttpApiUrl = "https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1"; VoiceEnrollmentService service = new VoiceEnrollmentService(apiKey); // Update the voice service.updateVoice(voiceId, fileUrl); logger.info("Update submitted. Request ID: {}", service.getLastRequestId()); }}
import com.alibaba.dashscope.audio.ttsv2.enrollment.VoiceEnrollmentService;import com.alibaba.dashscope.exception.InputRequiredException;import com.alibaba.dashscope.exception.NoApiKeyException;import com.alibaba.dashscope.utils.Constants;import org.slf4j.Logger;import org.slf4j.LoggerFactory;public class Main { public static String apiKey = System.getenv("DASHSCOPE_API_KEY"); // Replace with your API key if not using an environment variable private static String voiceId = "qwen-audio-3.0-tts-flash-myvoice-xxx"; // Replace with your actual value private static final Logger logger = LoggerFactory.getLogger(Main.class); public static void main(String[] args) throws NoApiKeyException, InputRequiredException { // The following uses the Singapore region. Replace {WorkspaceId} with your actual workspace ID. For other regions, modify the URL accordingly. Constants.baseHttpApiUrl = "https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1"; VoiceEnrollmentService service = new VoiceEnrollmentService(apiKey); // Delete the voice service.deleteVoice(voiceId); logger.info("Deletion submitted. Request ID: {}", service.getLastRequestId()); }}