语音合成-通义千问提供多种拟人音色,支持多语言及方言,并可在同一音色下输出多语言内容。系统可自适应语气,流畅处理复杂文本。
支持的模型
推荐使用通义千问3-TTS-Flash。
通义千问3-TTS-Flash拥有 49种音色,支持多种语言及方言。
通义千问-TTS最多拥有7种音色,且只支持中文和英文。
中国大陆(北京)
通义千问3-TTS-Flash
模型名称 | 版本 | 单价 | 最大输入字符数 | 支持的语种 | 免费额度(注) |
qwen3-tts-flash 当前能力等同 qwen3-tts-flash-2025-09-18 | 稳定版 | 0.8元/万字符 | 600 | 中文(普通话、北京、上海、四川、南京、陕西、闽南、天津、粤语)、英文、西班牙语、俄语、意大利语、法语、韩语、日语、德语、葡萄牙语 | 2025年11月13日0点前开通阿里云百炼:2000字符 2025年11月13日0点后开通阿里云百炼:1万字符 有效期:阿里云百炼开通后90天内 |
qwen3-tts-flash-2025-11-27 | 快照版 | 1万字符 有效期:阿里云百炼开通后90天内 | |||
qwen3-tts-flash-2025-09-18 | 快照版 | 2025年11月13日0点前开通阿里云百炼:2000字符 2025年11月13日0点后开通阿里云百炼:1万字符 有效期:阿里云百炼开通后90天内 |
按输入的字符数计费,计算规则如下:
一个汉字(包括简/繁体汉字、日文汉字和韩文汉字) = 2个字符
其他,如一个英文字母、一个标点符号、一个空格 = 1个字符
通义千问-TTS
模型名称 | 版本 | 上下文长度 | 最大输入 | 最大输出 | 输入成本 | 输出成本 | 免费额度 |
(Token数) | (每千Token) | ||||||
qwen-tts 当前与 qwen-tts-2025-04-10 能力相同 | 稳定版 | 8,192 | 512 | 7,680 | 0.0016元 | 0.01元 | 各100万Token 有效期:阿里云百炼开通后90天内 |
qwen-tts-latest 始终与最新快照版能力相同 | 最新版 | ||||||
qwen-tts-2025-05-22 | 快照版 | ||||||
qwen-tts-2025-04-10 | |||||||
音频转换为 Token 的规则:每1秒的音频对应 50个 Token 。若音频时长不足1秒,则按 50个 Token 计算。
国际(新加坡)
模型名称 | 版本 | 单价 | 最大输入字符数 | 支持的语种 |
qwen3-tts-flash 当前能力等同 qwen3-tts-flash-2025-09-18 | 稳定版 | 0.733924元/万字符 | 600 | 中文(普通话、北京、上海、四川、南京、陕西、闽南、天津、粤语)、英文、西班牙语、俄语、意大利语、法语、韩语、日语、德语、葡萄牙语 |
qwen3-tts-flash-2025-11-27 | 快照版 | |||
qwen3-tts-flash-2025-09-18 | 快照版 |
按输入的字符数计费,计算规则如下:
一个汉字(包括简/繁体汉字、日文汉字和韩文汉字) = 2个字符
其他,如一个英文字母、一个标点符号、一个空格 = 1个字符
功能特性
功能特性 | 通义千问3-TTS-Flash | 通义千问-TTS |
接入方式 | Java/Python SDK、RESTful API | |
流式输出 | 支持 | |
流式输入 | 不支持 | |
合成音频格式 |
| |
合成音频采样率 | 24kHz | |
时间戳 | 不支持 | |
语言 | 中文(普通话、北京、上海、四川、南京、陕西、闽南、天津、粤语)、英文、西班牙语、俄语、意大利语、法语、韩语、日语、德语、葡萄牙语,因音色而异,详情请参见支持的音色 | 中文(普通话、北京、上海、四川)、英文,因模型和音色而异,详情请参见支持的音色 |
声音复刻 | 不支持 | |
SSML | 不支持 | |
快速开始
准备工作
如果通过 DashScope SDK 进行调用,需要安装最新版SDK。DashScope Java SDK 版本需要不低于 2.21.9,DashScope Python SDK 版本需要不低于 1.24.6。
说明DashScope Python SDK中的
SpeechSynthesizer接口已统一为MultiModalConversation,使用新接口只需替换接口名称即可,其他参数完全兼容。
关键参数
text:用于指定文本voice:用于指定音色language_type:指定合成音频的语种,可选值有Chinese、English、German、Italian、Portuguese、Spanish、Japanese、Korean、French、Russian、Auto(默认)。
通过返回的url来获取合成的语音。URL 有效期为24 小时。
Python
# DashScope SDK 版本不低于 1.24.6
import os
import dashscope
# 以下为北京地域url,若使用新加坡地域的模型,需将url替换为:https://dashscope-intl.aliyuncs.com/api/v1
dashscope.base_http_api_url = 'https://dashscope.aliyuncs.com/api/v1'
text = "那我来给大家推荐一款T恤,这款呢真的是超级好看,这个颜色呢很显气质,而且呢也是搭配的绝佳单品,大家可以闭眼入,真的是非常好看,对身材的包容性也很好,不管啥身材的宝宝呢,穿上去都是很好看的。推荐宝宝们下单哦。"
# SpeechSynthesizer接口使用方法:dashscope.audio.qwen_tts.SpeechSynthesizer.call(...)
response = dashscope.MultiModalConversation.call(
model="qwen3-tts-flash",
# 新加坡和北京地域的API Key不同。获取API Key:https://help.aliyun.com/zh/model-studio/get-api-key
# 若没有配置环境变量,请用百炼API Key将下行替换为:api_key = "sk-xxx"
api_key=os.getenv("DASHSCOPE_API_KEY"),
text=text,
voice="Cherry",
language_type="Chinese", # 建议与文本语种一致,以获得正确的发音和自然的语调。
stream=False
)
print(response)Java
需要导入Gson依赖,若是使用Maven或者Gradle,添加依赖方式如下:
Maven
在pom.xml中添加如下内容:
<!-- https://mvnrepository.com/artifact/com.google.code.gson/gson -->
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.13.1</version>
</dependency>Gradle
在build.gradle中添加如下内容:
// https://mvnrepository.com/artifact/com.google.code.gson/gson
implementation("com.google.code.gson:gson:2.13.1")// DashScope SDK 版本不低于2.21.9
// 2.20.7 及以上版本支持指定 Dylan、Jada与 Sunny 三种音色
import com.alibaba.dashscope.aigc.multimodalconversation.AudioParameters;
import com.alibaba.dashscope.aigc.multimodalconversation.MultiModalConversation;
import com.alibaba.dashscope.aigc.multimodalconversation.MultiModalConversationParam;
import com.alibaba.dashscope.aigc.multimodalconversation.MultiModalConversationResult;
import com.alibaba.dashscope.exception.ApiException;
import com.alibaba.dashscope.exception.NoApiKeyException;
import com.alibaba.dashscope.exception.UploadFileException;
import com.alibaba.dashscope.protocol.Protocol;
import com.alibaba.dashscope.utils.Constants;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.net.URL;
public class Main {
private static final String MODEL = "qwen3-tts-flash";
public static void call() throws ApiException, NoApiKeyException, UploadFileException {
MultiModalConversation conv = new MultiModalConversation();
MultiModalConversationParam param = MultiModalConversationParam.builder()
// 新加坡和北京地域的API Key不同。获取API Key:https://help.aliyun.com/zh/model-studio/get-api-key
// 若没有配置环境变量,请用百炼API Key将下行替换为:.apiKey("sk-xxx")
.apiKey(System.getenv("DASHSCOPE_API_KEY"))
.model(MODEL)
.text("Today is a wonderful day to build something people love!")
.voice(AudioParameters.Voice.CHERRY)
.languageType("English") // 建议与文本语种一致,以获得正确的发音和自然的语调。
.build();
MultiModalConversationResult result = conv.call(param);
String audioUrl = result.getOutput().getAudio().getUrl();
System.out.print(audioUrl);
// 下载音频文件到本地
try (InputStream in = new URL(audioUrl).openStream();
FileOutputStream out = new FileOutputStream("downloaded_audio.wav")) {
byte[] buffer = new byte[1024];
int bytesRead;
while ((bytesRead = in.read(buffer)) != -1) {
out.write(buffer, 0, bytesRead);
}
System.out.println("\n音频文件已下载到本地: downloaded_audio.wav");
} catch (Exception e) {
System.out.println("\n下载音频文件时出错: " + e.getMessage());
}
}
public static void main(String[] args) {
try {
// 以下为北京地域url,若使用新加坡地域的模型,需将url替换为:https://dashscope-intl.aliyuncs.com/api/v1
Constants.baseHttpApiUrl = "https://dashscope.aliyuncs.com/api/v1";
call();
} catch (ApiException | NoApiKeyException | UploadFileException e) {
System.out.println(e.getMessage());
}
System.exit(0);
}
}cURL
# ======= 重要提示 =======
# 以下为北京地域url,若使用新加坡地域的模型,需将url替换为:https://dashscope-intl.aliyuncs.com/api/v1/services/aigc/multimodal-generation/generation
# 新加坡地域和北京地域的API Key不同。获取API Key:https://help.aliyun.com/zh/model-studio/get-api-key
# === 执行时请删除该注释 ===
curl -X POST 'https://dashscope.aliyuncs.com/api/v1/services/aigc/multimodal-generation/generation' \
-H "Authorization: Bearer $DASHSCOPE_API_KEY" \
-H 'Content-Type: application/json' \
-d '{
"model": "qwen3-tts-flash",
"input": {
"text": "那我来给大家推荐一款T恤,这款呢真的是超级好看,这个颜色呢很显气质,而且呢也是搭配的绝佳单品,大家可以闭眼入,真的是非常好看,对身材的包容性也很好,不管啥身材的宝宝呢,穿上去都是很好看的。推荐宝宝们下单哦。",
"voice": "Cherry",
"language_type": "Chinese"
}
}'实时播放
可以流式地将音频数据以 Base64 格式进行输出,并在最后一个数据包中包含完整音频的 URL。
Python
# DashScope SDK 版本不低于 1.24.6
# coding=utf-8
#
# Installation instructions for pyaudio:
# APPLE Mac OS X
# brew install portaudio
# pip install pyaudio
# Debian/Ubuntu
# sudo apt-get install python-pyaudio python3-pyaudio
# or
# pip install pyaudio
# CentOS
# sudo yum install -y portaudio portaudio-devel && pip install pyaudio
# Microsoft Windows
# python -m pip install pyaudio
import os
import dashscope
import pyaudio
import time
import base64
import numpy as np
# 以下为北京地域url,若使用新加坡地域的模型,需将url替换为:https://dashscope-intl.aliyuncs.com/api/v1
dashscope.base_http_api_url = 'https://dashscope.aliyuncs.com/api/v1'
p = pyaudio.PyAudio()
# 创建音频流
stream = p.open(format=pyaudio.paInt16,
channels=1,
rate=24000,
output=True)
text = "你好啊,我是通义千问"
response = dashscope.MultiModalConversation.call(
# 新加坡和北京地域的API Key不同。获取API Key:https://help.aliyun.com/zh/model-studio/get-api-key
# 若没有配置环境变量,请用百炼API Key将下行替换为:api_key = "sk-xxx"
api_key=os.getenv("DASHSCOPE_API_KEY"),
model="qwen3-tts-flash",
text=text,
voice="Cherry",
language_type="Chinese", # 建议与文本语种一致,以获得正确的发音和自然的语调。
stream=True
)
for chunk in response:
if chunk.output is not None:
audio = chunk.output.audio
if audio.data is not None:
wav_bytes = base64.b64decode(audio.data)
audio_np = np.frombuffer(wav_bytes, dtype=np.int16)
# 直接播放音频数据
stream.write(audio_np.tobytes())
if chunk.output.finish_reason == "stop":
print("finish at: {} ", chunk.output.audio.expires_at)
time.sleep(0.8)
# 清理资源
stream.stop_stream()
stream.close()
p.terminate()
Java
需要导入Gson依赖,若是使用Maven或者Gradle,添加依赖方式如下:
Maven
在pom.xml中添加如下内容:
<!-- https://mvnrepository.com/artifact/com.google.code.gson/gson -->
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.13.1</version>
</dependency>Gradle
在build.gradle中添加如下内容:
// https://mvnrepository.com/artifact/com.google.code.gson/gson
implementation("com.google.code.gson:gson:2.13.1")// DashScope SDK 版本不低于2.21.9
// 2.20.7 及以上版本支持指定 Dylan、Jada与 Sunny 三种音色
import com.alibaba.dashscope.aigc.multimodalconversation.AudioParameters;
import com.alibaba.dashscope.aigc.multimodalconversation.MultiModalConversation;
import com.alibaba.dashscope.aigc.multimodalconversation.MultiModalConversationParam;
import com.alibaba.dashscope.aigc.multimodalconversation.MultiModalConversationResult;
import com.alibaba.dashscope.exception.ApiException;
import com.alibaba.dashscope.exception.NoApiKeyException;
import com.alibaba.dashscope.exception.UploadFileException;
import com.alibaba.dashscope.protocol.Protocol;
import com.alibaba.dashscope.utils.Constants;
import io.reactivex.Flowable;
import javax.sound.sampled.*;
import java.util.Base64;
public class Main {
private static final String MODEL = "qwen3-tts-flash";
public static void streamCall() throws ApiException, NoApiKeyException, UploadFileException {
MultiModalConversation conv = new MultiModalConversation();
MultiModalConversationParam param = MultiModalConversationParam.builder()
// 新加坡和北京地域的API Key不同。获取API Key:https://help.aliyun.com/zh/model-studio/get-api-key
// 若没有配置环境变量,请用百炼API Key将下行替换为:.apiKey("sk-xxx")
.apiKey(System.getenv("DASHSCOPE_API_KEY"))
.model(MODEL)
.text("Today is a wonderful day to build something people love!")
.voice(AudioParameters.Voice.CHERRY)
.languageType("English") // 建议与文本语种一致,以获得正确的发音和自然的语调。
.build();
Flowable<MultiModalConversationResult> result = conv.streamCall(param);
result.blockingForEach(r -> {
try {
// 1. 获取Base64编码的音频数据
String base64Data = r.getOutput().getAudio().getData();
byte[] audioBytes = Base64.getDecoder().decode(base64Data);
// 2. 配置音频格式(根据API返回的音频格式调整)
AudioFormat format = new AudioFormat(
AudioFormat.Encoding.PCM_SIGNED,
24000, // 采样率(需与API返回格式一致)
16, // 采样位数
1, // 声道数
2, // 帧大小(位数/字节数)
16000, // 数据传输率
false // 是否压缩
);
// 3. 实时播放音频数据
DataLine.Info info = new DataLine.Info(SourceDataLine.class, format);
try (SourceDataLine line = (SourceDataLine) AudioSystem.getLine(info)) {
if (line != null) {
line.open(format);
line.start();
line.write(audioBytes, 0, audioBytes.length);
line.drain();
}
}
} catch (LineUnavailableException e) {
e.printStackTrace();
}
});
}
public static void main(String[] args) {
// 以下为北京地域url,若使用新加坡地域的模型,需将url替换为:https://dashscope-intl.aliyuncs.com/api/v1
Constants.baseHttpApiUrl = "https://dashscope.aliyuncs.com/api/v1";
try {
streamCall();
} catch (ApiException | NoApiKeyException | UploadFileException e) {
System.out.println(e.getMessage());
}
System.exit(0);
}
}
cURL
# ======= 重要提示 =======
# 以下为北京地域url,若使用新加坡地域的模型,需将url替换为:https://dashscope-intl.aliyuncs.com/api/v1/services/aigc/multimodal-generation/generation
# 新加坡地域和北京地域的API Key不同。获取API Key:https://help.aliyun.com/zh/model-studio/get-api-key
# === 执行时请删除该注释 ===
curl -X POST 'https://dashscope.aliyuncs.com/api/v1/services/aigc/multimodal-generation/generation' \
-H "Authorization: Bearer $DASHSCOPE_API_KEY" \
-H 'Content-Type: application/json' \
-H 'X-DashScope-SSE: enable' \
-d '{
"model": "qwen3-tts-flash",
"input": {
"text": "那我来给大家推荐一款T恤,这款呢真的是超级好看,这个颜色呢很显气质,而且呢也是搭配的绝佳单品,大家可以闭眼入,真的是非常好看,对身材的包容性也很好,不管啥身材的宝宝呢,穿上去都是很好看的。推荐宝宝们下单哦。",
"voice": "Cherry",
"language_type": "Chinese"
}
}'API 参考
请参见语音合成(Qwen-TTS)。
支持的音色
通义千问3-TTS-Flash
不同模型支持的音色有所差异,使用时将请求参数voice设置为音色列表中voice参数列对应的值。
通义千问-TTS
不同模型支持的音色有所差异,使用时将请求参数voice设置为音色列表中voice参数列对应的值。
常见问题
Q:音频文件链接的有效期是多久?
A:24小时后音频文件链接将失效。