Tradução de apoio para consulta. Código e identificadores técnicos preservados. Consultar referência original ↗
Crie uma voz clonada
OpenAPI
openapi: 3.1.0
info:
title: Qwen Voice Cloning API — Create voice
version: 1.0.0
servers:
- url: https://maas.qwencloudapi.com/api/v1
description: Singapore
security:
- BearerAuth: []
paths:
/services/audio/tts/customization:
post:
operationId: createVoiceCloningQwen
summary: Create a cloned voice
description: Clone a voice from audio for Qwen TTS or Qwen-Omni-Realtime models. Returns a `voice` name that you can use in [Qwen TTS](/api-reference/speech-synthesis/qwen-tts), [Realtime streaming TTS](/api-reference/speech-synthesis/qwen-tts-realtime/client-events), or [Realtime Multimodal API](/api-reference/real-time-multimodal/client-events) calls.
requestBody:
required: true
content:
application/json:
schema:
$ref: "#/components/schemas/CreateRequest"
responses:
"200":
description: Voice created successfully
content:
application/json:
schema:
$ref: "#/components/schemas/CreateResponse"
"400":
description: Invalid request
content:
application/json:
schema:
$ref: "#/components/schemas/ErrorResponse"
x-codeSamples:
- lang: bash
label: cURL
source: |-
curl -X POST https://maas.qwencloudapi.com/api/v1/services/audio/tts/customization \
-H "Authorization: Bearer $DASHSCOPE_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "qwen-voice-enrollment",
"input": {
"action": "create",
"target_model": "qwen3.5-omni-plus-realtime",
"preferred_name": "guanyu",
"audio": {
"data": "https://your-audio-url.wav"
}
}
}'
- lang: python
label: Python
source: |-
import os
import requests
import base64, pathlib
target_model = "qwen3.5-omni-plus-realtime"
preferred_name = "guanyu"
audio_mime_type = "audio/mpeg"
file_path = pathlib.Path("input.mp3")
base64_str = base64.b64encode(file_path.read_bytes()).decode()
data_uri = f"data:{audio_mime_type};base64,{base64_str}"
api_key = os.getenv("DASHSCOPE_API_KEY")
url = "https://maas.qwencloudapi.com/api/v1/services/audio/tts/customization"
payload = {
"model": "qwen-voice-enrollment",
"input": {
"action": "create",
"target_model": target_model,
"preferred_name": preferred_name,
"audio": {
"data": data_uri
}
}
}
headers = {
"Authorization": f"Bearer {api_key}",
"Content-Type": "application/json"
}
resp = requests.post(url, json=payload, headers=headers)
if resp.status_code == 200:
data = resp.json()
voice = data["output"]["voice"]
print(f"Generated voice parameter: {voice}")
else:
print("Request failed:", resp.status_code, resp.text)
- lang: java
label: Java
source: |-
import com.google.gson.Gson;
import com.google.gson.JsonObject;
import java.io.*;
import java.net.HttpURLConnection;
import java.net.URL;
import java.nio.file.*;
import java.util.Base64;
public class Main {
private static final String TARGET_MODEL = "qwen3.5-omni-plus-realtime";
private static final String PREFERRED_NAME = "guanyu";
private static final String AUDIO_FILE = "input.mp3";
private static final String AUDIO_MIME_TYPE = "audio/mpeg";
public static String toDataUrl(String filePath) throws Exception {
byte[] bytes = Files.readAllBytes(Paths.get(filePath));
String encoded = Base64.getEncoder().encodeToString(bytes);
return "data:" + AUDIO_MIME_TYPE + ";base64," + encoded;
}
public static void main(String[] args) {
String apiKey = System.getenv("DASHSCOPE_API_KEY");
String apiUrl = "https://maas.qwencloudapi.com/api/v1/services/audio/tts/customization";
try {
String jsonPayload =
"{"
+ "\"model\": \"qwen-voice-enrollment\","
+ "\"input\": {"
+ "\"action\": \"create\","
+ "\"target_model\": \"" + TARGET_MODEL + "\","
+ "\"preferred_name\": \"" + PREFERRED_NAME + "\","
+ "\"audio\": {"
+ "\"data\": \"" + toDataUrl(AUDIO_FILE) + "\""
+ "}"
+ "}"
+ "}";
HttpURLConnection con = (HttpURLConnection) new URL(apiUrl).openConnection();
con.setRequestMethod("POST");
con.setRequestProperty("Authorization", "Bearer " + apiKey);
con.setRequestProperty("Content-Type", "application/json");
con.setDoOutput(true);
try (OutputStream os = con.getOutputStream()) {
os.write(jsonPayload.getBytes("UTF-8"));
}
int status = con.getResponseCode();
InputStream is = (status >= 200 && status < 300)
? con.getInputStream()
: con.getErrorStream();
StringBuilder response = new StringBuilder();
try (BufferedReader br = new BufferedReader(new InputStreamReader(is, "UTF-8"))) {
String line;
while ((line = br.readLine()) != null) {
response.append(line);
}
}
System.out.println("HTTP status code: " + status);
if (status == 200) {
Gson gson = new Gson();
JsonObject jsonObj = gson.fromJson(response.toString(), JsonObject.class);
String voice = jsonObj.getAsJsonObject("output").get("voice").getAsString();
System.out.println("Generated voice parameter: " + voice);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
components:
schemas:
CreateRequest:
type: object
required:
- model
- input
properties:
model:
type: string
description: Fixed to `qwen-voice-enrollment`.
enum:
- qwen-voice-enrollment
example: qwen-voice-enrollment
input:
type: object
required:
- action
- target_model
- audio
properties:
action:
type: string
description: Fixed to `create`.
enum:
- create
example: create
target_model:
type: string
description: Target model for the cloned voice. Must match the model in subsequent API calls.
enum:
- qwen3.5-omni-plus-realtime
- qwen3.5-omni-flash-realtime
example: qwen3.5-omni-plus-realtime
preferred_name:
type: string
description: "Voice name keyword (digits, letters, underscores, max 16 characters). Appears in the generated voice name. Example: `guanyu` produces `qwen-tts-vc-guanyu-voice-20250812105009984-838b`."
maxLength: 16
pattern: ^[a-zA-Z0-9_]+$
example: guanyu
audio:
type: object
required:
- data
description: Audio data for cloning.
properties:
data:
type: string
description: "**Data URL** (Base64): `data:<mediatype>;base64,<data>` where `<mediatype>` is `audio/wav`, `audio/mpeg`, or `audio/mp4`. Keep encoded data under 10 MB. **Audio URL**: publicly accessible URL (no auth required)."
example: https://your-audio-url.wav
text:
type: string
description: Text matching the audio content. The server validates the match and returns `Audio.PreprocessError` if significantly different.
example: Hello, this is a sample text for voice cloning.
language:
type: string
description: Audio language code. Must match the audio language if specified.
enum:
- zh
- en
- de
- it
- pt
- es
- ja
- ko
- fr
- ru
example: zh
CreateResponse:
type: object
properties:
output:
type: object
properties:
voice:
type: string
description: Generated voice name. Pass as the `voice` parameter in subsequent Qwen TTS or Realtime Multimodal API calls.
example: qwen-omni-vc-guanyu-voice-20250812105009984-838b
target_model:
type: string
description: Target model bound to this voice.
example: qwen3.5-omni-plus-realtime
fallback_mode:
type: boolean
description: "`true` if the voice was created in degraded mode due to poor audio quality or text mismatch."
example: false
fallback_reason:
type: string
description: "Reason for degradation. Possible values: `no_merged_segments`, `no_valid_asr_segments`, etc. Only returned when `fallback_mode` is `true`."
usage:
type: object
properties:
count:
type: integer
description: Billed voice creation operations. Always `1`.
example: 1
request_id:
type: string
description: Request ID for troubleshooting.
example: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
ErrorResponse:
type: object
properties:
request_id:
type: string
example: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
code:
type: string
example: Audio.PreprocessError
message:
type: string
example: Audio preprocessing failed
securitySchemes:
BearerAuth:
type: http
scheme: bearer
description: DashScope API key. Get one at [API key](/api-reference/preparation/api-key).