Skip to main content

Qwen-Audio-TTS Python SDK

前提条件

快速开始

示例使用新加坡。将代码中的 {WorkspaceId} 替换为实际的业务空间 ID。运行后,音频保存到当前目录的 output.mp3。
# coding=utf-8

import os

import dashscope

# If the environment variable is not configured, set your API key directly: api_key = "sk-xxx"
# The following is the configuration for the Singapore region. Replace "{WorkspaceId}" with your actual workspace ID. The region value varies by region.
client = dashscope.Client(
    api_key=os.environ.get('DASHSCOPE_API_KEY'),
    workspace="{WorkspaceId}",
    region="ap-southeast-1",
)

# Model
model = "qwen-audio-3.0-tts-flash"
# Voice
voice = "longanhuan_v3.6"

# Send the text to synthesize and get the binary audio
audio = client.audio.tts.synthesize("今天天气怎么样?", model=model, voice=voice)

# Save the audio to a local file
with open('output.mp3', 'wb') as f:
    f.write(audio)

更多示例与参考