API

简介

我们通过 Qwen API 更新了 Qwen-TTS ( qwen-tts-latest or qwen-tts-2025-05-22 ) 的最新版本。Qwen-TTS 使用了超过 300 万小时的大规模语料库进行训练,合成效果实现了人类级别的自然度和表现力。比较亮眼的是,Qwen-TTS 会根据输入文本自动调整韵律、节奏和情绪变化。此外,Qwen-TTS 支持生成三种中文方言,包括北京话、上海话和四川话。

目前,Qwen-TTS 支持七种中英双语音色,包括 Cherry、Ethan、Chelsie、Serena、Dylan(北京话)、Jada(上海话) 和 Sunny(四川话),更多语言和风格选项即将在近期推出。

中文方言样例

这里有一些样例展示了 Qwen-TTS 在中文方言上的自然生成能力。

音色方言种类文本合成样例
Dylan北京话我们家那边后面有一个后山,就护城河那边,完了呢我们就在山上啊就其实也没什么,就是在土坡上跑来跑去,然后谁捡个那个嗯比较威风的棍,完了我们就呃得瞎打呃,要不就是什么掏个洞啊什么的。
得有自己的想法,别净跟着别人瞎起哄,多动动脑子,有点儿结构化的思维啥的。
Jada上海话侬只小赤佬,啊呀,数学句子错它八道题,还想吃肯德基啊!夜到麻将队三缺一啊,嘿嘿,叫阿三头来顶嘛!哦,提前上料这样产品,还要卖 300 块硬币啊。
侬来帮伊向暖吧,天光已经暗转亮哉。
Sunny四川话胖娃胖嘟嘟,骑马上成都,成都又好耍。胖娃骑白马,白马跳得高。胖娃耍关刀,关刀耍得圆。胖娃吃汤圆。
他一辈子的使命就是不停地爬哟,爬到大海头上去,不管有好多远!

额外结果

Qwen-TTS 生成的效果目前已经达到了人类水平,其在 SeedTTS-Eval 评测集上的指标如下:

音色词错误率 WER (↓)音色相似度 SIM (↑)
zhenhardzhenhard
Chelsie1.2562.0046.1710.6580.4730.662
Serena1.4952.2067.3940.8040.5080.803
Ethan1.4891.9696.7540.7770.5580.779
Cherry1.2091.9676.0690.7990.6640.801

下面是这四种音色对应的一些中英双语样例:

音色文本合成样例
Cherry对吧!我就特别喜欢这种超市,尤其是过年的时候,去逛超市就觉得超级超级开心,然后买点儿东西就要买好多好多东西,这个也想买那个也想买,然后买一堆东西带回去。
Take a look at http://www.granite.ab.ca/access/email.
Ethan啊?真的假的?他们俩拍吻戏。可是我觉得他们两个没有 CP 感欸。
Jane's eyes wide with terror, she screamed, "The brakes aren't working! What do we do now? We're completely trapped, and we're heading straight for that wall, I can't stop it!" Then, a strange calm washed over her as she murmured, "Well, at least the view was nice. It's almost poetic, this beautiful scene for our grand finale, isn't it?"
Chelsie哼!还让不让人好好减肥啦,不行,你要请我一顿好的赔偿我哦。
"Oh my gosh! Are we really going to the Maldives? That’s unbelievable!" Jennie squealed.
Serena小狗,么么么么么,你快看它,它好可爱。哇,它倒立了是不是,太厉害了!好呀,我们要不要用狗粮把它拐回家,嗯?
You can call me directly at 4257037344 or my cell 4254447474 or send me a meeting request with all the appropriate information.

使用方法

通过 Qwen API 使用 Qwen-TTS 是非常简单的,我们在下面提供了一个简单的代码片段以供体验:

import os
import requests
import dashscope


def get_api_key():
    api_key = os.getenv("DASHSCOPE_API_KEY")
    if not api_key:
        raise EnvironmentError("DASHSCOPE_API_KEY environment variable not set.")
    return api_key


def synthesize_speech(text, voice="Dylan", model="qwen-tts-latest"):
    api_key = get_api_key()
    try:
        response = dashscope.audio.qwen_tts.SpeechSynthesizer.call(
            model=model,
            api_key=api_key,
            text=text,
            voice=voice,
        )
        
        # Check if response is None
        if response is None:
            raise RuntimeError("API call returned None response")
        
        # Check if response.output is None
        if response.output is None:
            raise RuntimeError("API call failed: response.output is None")
        
        # Check if response.output.audio exists
        if not hasattr(response.output, 'audio') or response.output.audio is None:
            raise RuntimeError("API call failed: response.output.audio is None or missing")
        
        audio_url = response.output.audio["url"]
        return audio_url
    except Exception as e:
        raise RuntimeError(f"Speech synthesis failed: {e}")


def download_audio(audio_url, save_path):
    try:
        resp = requests.get(audio_url, timeout=10)
        resp.raise_for_status()
        with open(save_path, 'wb') as f:
            f.write(resp.content)
        print(f"Audio file saved to: {save_path}")
    except Exception as e:
        raise RuntimeError(f"Download failed: {e}")


def main():
    text = (
        """哟,您猜怎么着?今儿个我看NBA,库里投篮跟闹着玩似的,张手就来,篮筐都得喊他“亲爹”了"""
    )
    save_path = "downloaded_audio.wav"
    try:
        audio_url = synthesize_speech(text)
        download_audio(audio_url, save_path)
    except Exception as e:
        print(e)


if __name__ == "__main__":
    main()

结语

Qwen-TTS是一个语音合成模型,支持中英双语以及几种中文方言的合成,它旨在通过API提供自然和富有表现力的语音生成能力。尽管它目前已经表现出良好的效果,但我们期待着未来能对其进一步改进,并支持更为广泛的语言。