Qwen-声音设计
复制成功!
立即体验加入对比
语音合成
概述
语音合成
千问voice-design模型是千问语音模型的声音设计系列模型,仅需输入简单的文字描述,即可迅速设计出符合要求的相关声音。结合qwen3-tts-vd-realtime模型使用,可设计输出10个语种的语音。且合成音频可以根据文本自适应调节语气,对复杂文本合成也有较好的处理能力。
输入
文本
输出
音频
功能
定价
- 声音复刻及声音设计¥0.2每次
速率限制
- RPM每分钟请求数180
API 参考
获取 API Key复制成功!
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
import requests
import base64
import os
def create_voice_and_play():
api_key = os.getenv("DASHSCOPE_API_KEY")
if not api_key:
print("错误: 未找到DASHSCOPE_API_KEY环境变量,请先设置API Key")
return None, None, None
headers = {
"Authorization": f"Bearer {api_key}",
"Content-Type": "application/json"
}
data = {
"model": "qwen-voice-design",
"input": {
"action": "create",
"target_model": "qwen3-tts-vd-realtime-2025-12-16",
"voice_prompt": "沉稳的中年男性播音员,音色低沉浑厚,富有磁性,语速平稳,吐字清晰,适合用于新闻播报或纪录片解说。",
"preview_text": "各位听众朋友,大家好,欢迎收听晚间新闻。",
"preferred_name": "announcer",
"language": "zh"
},
"parameters": {
"sample_rate": 24000,
"response_format": "wav"
}
}
url = "https://dashscope.aliyuncs.com/api/v1/services/audio/tts/customization"
try:
response = requests.post(
url,
headers=headers,
json=data,
timeout=60
)
if response.status_code == 200:
result = response.json()
voice_name = result["output"]["voice"]
print(f"音色名称: {voice_name}")
base64_audio = result["output"]["preview_audio"]["data"]
audio_bytes = base64.b64decode(base64_audio)
filename = f"{voice_name}_preview.wav"
with open(filename, 'wb') as f:
f.write(audio_bytes)
print(f"音频已保存到本地文件: {filename}")
print(f"文件路径: {os.path.abspath(filename)}")
return voice_name, audio_bytes, filename
else:
print(f"请求失败,状态码: {response.status_code}")
print(f"响应内容: {response.text}")
return None, None, None
except requests.exceptions.RequestException as e:
print(f"网络请求发生错误: {e}")
return None, None, None
except KeyError as e:
print(f"响应数据格式错误,缺少必要的字段: {e}")
print(f"响应内容: {response.text if 'response' in locals() else 'No response'}")
return None, None, None
except Exception as e:
print(f"发生未知错误: {e}")
return None, None, None
if __name__ == "__main__":
voice_name, audio_data, saved_filename = create_voice_and_play()
if voice_name:
print(f"\n成功创建音色 '{voice_name}'")
print(f"音频文件已保存: '{saved_filename}'")
print(f"文件大小: {os.path.getsize(saved_filename)} 字节")
else:
print("\n音色创建失败")