Qwen3-TTS-VD-Realtime

复制成功!
加入对比
语音合成

概述

语音合成

千问3-TTS-VD模型是通义实验室最新推出的实时语音合成大模型,可对qwen3-voice-design服务设计的声音进行高保真实时语音合成,且同一音色支持11个语种的语音输出。该模型经过海量数据训练,合成音频可以根据文本自适应调节语气,对复杂文本合成也有较好的处理能力。该模型为2025年12月16日快照版本模型。

输入

文本

输出

音频

功能

前缀补全

您可在调用通义千问 API 时启用 Partial Mode,确保模型严格基于您的起始文本进行生成。查看文档

函数调用

您可以使用 函数调用 功能,通过引入外部工具,使得大模型可以与外部世界进行交互。查看文档

缓存

Context Cache 技术会缓存长上下文请求的公共前缀,减少推理时的重复计算,提升响应速度同时降低您的使用成本。查看文档

结构化输出

开启结构化输出功能可以确保大模型输出标准格式的 JSON 字符串。查看文档

批量任务

联网搜索

启用联网检索功能后,模型将基于实时检索数据进行回复。查看文档

微调

定价

  • 语音合成
    ¥1每万字符

速率限制

  • RPM每分钟请求数
    180

API 参考

获取 API Key
复制成功!
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
import os
import base64
import threading
import time
import dashscope
from dashscope.audio.qwen_tts_realtime import *

qwen_tts_realtime: QwenTtsRealtime = None
text_to_synthesize = [
    '今天天气怎么样?'
]

DO_VIDEO_TEST = False

def init_dashscope_api_key():
    """
        Set your DashScope API-key. More information:
        https://github.com/aliyun/alibabacloud-bailian-speech-demo/blob/master/PREREQUISITES.md
    """
    if 'DASHSCOPE_API_KEY' in os.environ:
        dashscope.api_key = os.environ[
            'DASHSCOPE_API_KEY']  # load API-key from environment variable DASHSCOPE_API_KEY
    else:
        dashscope.api_key = 'your-dashscope-api-key'  # set API-key manually



class MyCallback(QwenTtsRealtimeCallback):
    def __init__(self):
        self.complete_event = threading.Event()
        self.file = open('result_24k.pcm', 'wb')

    def on_open(self) -> None:
        print('connection opened, init player')

    def on_close(self, close_status_code, close_msg) -> None:
        self.file.close()
        print('connection closed with code: {}, msg: {}, destroy player'.format(close_status_code, close_msg))

    def on_event(self, response: str) -> None:
        try:
            global qwen_tts_realtime
            type = response['type']
            if 'session.created' == type:
                print('start session: {}'.format(response['session']['id']))
            if 'response.audio.delta' == type:
                recv_audio_b64 = response['delta']
                self.file.write(base64.b64decode(recv_audio_b64))
            if 'response.done' == type:
                print(f'response {qwen_tts_realtime.get_last_response_id()} done')
            if 'session.finished' == type:
                print('session finished')
                self.complete_event.set()
        except Exception as e:
            print('[Error] {}'.format(e))
            return

    def wait_for_finished(self):
        self.complete_event.wait()


if __name__  == '__main__':
    init_dashscope_api_key()

    print('Initializing ...')

    callback = MyCallback()

    qwen_tts_realtime = QwenTtsRealtime(
        model='qwen3-tts-vd-realtime-2025-12-16',
        callback=callback, 
        url='wss://dashscope.aliyuncs.com/api-ws/v1/realtime'
        )

    qwen_tts_realtime.connect()
    qwen_tts_realtime.update_session(
        # 将下面的音色替换为实际的设计音色
        voice = 'your_design_voice',
        response_format = AudioFormat.PCM_24000HZ_MONO_16BIT,
        mode = 'server_commit'        
    )
    for text_chunk in text_to_synthesize:
        print(f'send texd: {text_chunk}')
        qwen_tts_realtime.append_text(text_chunk)
        time.sleep(0.1)
    qwen_tts_realtime.finish()
    callback.wait_for_finished()
    print('[Metric] session: {}, first audio delay: {}'.format(
                    qwen_tts_realtime.get_session_id(), 
                    qwen_tts_realtime.get_first_audio_delay(),
                    ))