語音合成-通義千問提供多種擬人音色,支援多語言及方言,並可在同一音色下輸出多語言內容。系統可自適應語氣,流暢處理複雜文本。
支援的模型
推薦使用通義千問3-TTS-Flash。
通義千問3-TTS-Flash擁有 49種音色,支援多種語言及方言。
通義千問-TTS最多擁有7種音色,且只支援中文和英文。
國際(新加坡)
模型名稱 | 版本 | 單價 | 最大輸入字元數 | 支援的語種 | 免費額度(注) |
qwen3-tts-flash 當前能力等同 qwen3-tts-flash-2025-09-18 | 穩定版 | $0.1/萬字元 | 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個字元
中國大陸(北京)
通義千問3-TTS-Flash
模型名稱 | 版本 | 單價 | 最大輸入字元數 | 支援的語種 |
qwen3-tts-flash 當前能力等同 qwen3-tts-flash-2025-09-18 | 穩定版 | $0.114682/萬字元 | 600 | 中文(普通話、北京、上海、四川、南京、陝西、閩南、天津、粵語)、英文、西班牙語、俄語、意大利語、法語、韓語、日語、德語、葡萄牙語 |
qwen3-tts-flash-2025-11-27 | 快照版 | |||
qwen3-tts-flash-2025-09-18 | 快照版 |
按輸入的字元數計費,計算規則如下:
一個漢字(包括簡/繁體漢字、日文漢字和韓文漢字) = 2個字元
其他,如一個英文字母、一個標點符號、一個空格 = 1個字元
通義千問-TTS
模型名稱 | 版本 | 上下文長度 | 最大輸入 | 最大輸出 | 輸入成本 | 輸出成本 |
(Token數) | (每千Token) | |||||
qwen-tts 當前與 qwen-tts-2025-04-10 能力相同 | 穩定版 | 8,192 | 512 | 7,680 | $0.230 | $1.434 |
qwen-tts-latest 始終與最新快照版能力相同 | 最新版 | |||||
qwen-tts-2025-05-22 | 快照版 | |||||
qwen-tts-2025-04-10 | ||||||
音頻轉換為 Token 的規則:每1秒的音頻對應 50個 Token 。若音頻時間長度不足1秒,則按 50個 Token 計算。
功能特性
功能特性 | 通義千問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.aliyuncs.com/api/v1
dashscope.base_http_api_url = 'https://dashscope-intl.aliyuncs.com/api/v1'
text = "Today is a wonderful day to build something people love!"
# SpeechSynthesizer介面使用方法:dashscope.audio.qwen_tts.SpeechSynthesizer.call(...)
response = dashscope.MultiModalConversation.call(
model="qwen3-tts-flash",
# 新加坡地區和北京地區的API Key不同。擷取API Key:https://www.alibabacloud.com/help/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="English", # 建議與文本語種一致,以獲得正確的發音和自然的語調。
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://www.alibabacloud.com/help/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) {
// 以下為新加坡地區url,若使用北京地區的模型,需將url替換為:https://dashscope.aliyuncs.com/api/v1
Constants.baseHttpApiUrl = "https://dashscope-intl.aliyuncs.com/api/v1";
try {
call();
} catch (ApiException | NoApiKeyException | UploadFileException e) {
System.out.println(e.getMessage());
}
System.exit(0);
}
}cURL
# ======= 重要提示 =======
# 以下為新加坡地區url,若使用北京地區的模型,需將url替換為:https://dashscope.aliyuncs.com/api/v1/services/aigc/multimodal-generation/generation
# 新加坡地區和北京地區的API Key不同。擷取API Key:https://www.alibabacloud.com/help/zh/model-studio/get-api-key
# === 執行時請刪除該注釋 ===
curl -X POST 'https://dashscope-intl.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": "Today is a wonderful day to build something people love!",
"voice": "Cherry",
"language_type": "English"
}
}'即時播放
可以流式地將音頻資料以 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.aliyuncs.com/api/v1
dashscope.base_http_api_url = 'https://dashscope-intl.aliyuncs.com/api/v1'
p = pyaudio.PyAudio()
# 建立音頻流
stream = p.open(format=pyaudio.paInt16,
channels=1,
rate=24000,
output=True)
text = "Today is a wonderful day to build something people love!"
response = dashscope.MultiModalConversation.call(
# 新加坡地區和北京地區的API Key不同。擷取API Key:https://www.alibabacloud.com/help/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="English", # 建議與文本語種一致,以獲得正確的發音和自然的語調。
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.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://www.alibabacloud.com/help/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.aliyuncs.com/api/v1
Constants.baseHttpApiUrl = "https://dashscope-intl.aliyuncs.com/api/v1";
try {
streamCall();
} catch (ApiException | NoApiKeyException | UploadFileException e) {
System.out.println(e.getMessage());
}
System.exit(0);
}
}
cURL
# ======= 重要提示 =======
# 以下為新加坡地區url,若使用北京地區的模型,需將url替換為:https://dashscope.aliyuncs.com/api/v1/services/aigc/multimodal-generation/generation
# 新加坡地區和北京地區的API Key不同。擷取API Key:https://www.alibabacloud.com/help/zh/model-studio/get-api-key
# === 執行時請刪除該注釋 ===
curl -X POST 'https://dashscope-intl.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": "Today is a wonderful day to build something people love!",
"voice": "Cherry",
"language_type": "Chinese"
}
}'API 參考
請參見語音合成(Qwen-TTS)。
支援的音色
通義千問3-TTS-Flash
不同模型支援的音色有所差異,使用時將請求參數voice設定為音色列表中voice參數列對應的值。
通義千問-TTS
不同模型支援的音色有所差異,使用時將請求參數voice設定為音色列表中voice參數列對應的值。
常見問題
Q:音頻檔案連結的有效期間是多久?
A:24小時後音頻檔案連結將失效。