Documentation Index
Fetch the complete documentation index at: /llms.txt
Use this file to discover all available pages before exploring further.
{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)