| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- #!/usr/bin/env python3
- """
- list-aliyun-voices.py — 列阿里云百炼 TTS 模型的 voice 池
- 按服务分类尝试不同 endpoint
- """
- import os, sys, json, requests
- env_file = "/data/ai/audio/server/.env"
- if os.path.exists(env_file):
- with open(env_file) as f:
- for line in f:
- if line.startswith("DASHSCOPE_API_KEY="):
- api_key = line.split("=", 1)[1].strip()
- break
- else:
- api_key = os.environ.get("DASHSCOPE_API_KEY", "")
- if not api_key:
- print("ERROR: DASHSCOPE_API_KEY not set", file=sys.stderr)
- sys.exit(1)
- # 每个模型的 url + voices 路径
- configs = [
- ("cosyvoice-v3-flash", "https://dashscope.aliyuncs.com/api/v1/services/audio/tts/SpeechSynthesizer/voices", {"model": "cosyvoice-v3-flash"}),
- ("cosyvoice-v2", "https://dashscope.aliyuncs.com/api/v1/services/audio/tts/SpeechSynthesizer/voices", {"model": "cosyvoice-v2"}),
- ("cosyvoice-v1", "https://dashscope.aliyuncs.com/api/v1/services/audio/tts/SpeechSynthesizer/voices", {"model": "cosyvoice-v1"}),
- ("qwen3-tts-instruct-flash", "https://dashscope.aliyuncs.com/api/v1/services/aigc/multimodal-generation/voices", {"model": "qwen3-tts-instruct-flash"}),
- ("qwen3-tts-flash", "https://dashscope.aliyuncs.com/api/v1/services/aigc/multimodal-generation/voices", {"model": "qwen3-tts-flash"}),
- ("sambert-zhichu-v1", "https://dashscope.aliyuncs.com/api/v1/services/audio/tts/SpeechSynthesizer/voices", {"model": "sambert-zhichu-v1"}),
- ]
- results = {} # model -> [voices]
- for model, url, payload in configs:
- try:
- r = requests.post(url, headers={
- "Authorization": f"Bearer {api_key}",
- "Content-Type": "application/json",
- }, json=payload, timeout=15)
- d = r.json()
- if d.get("code"):
- print(f" [{model}] skip: {d.get('message')[:80]}", file=sys.stderr)
- continue
- # 不同的返回结构都试
- voices = (
- d.get("output", {}).get("voices")
- or d.get("output", {}).get("voice_list")
- or d.get("output", {}).get("data")
- or []
- )
- results[model] = voices
- print(f" [{model}] ok: {len(voices)} voices (url: {url.split('/')[-2]}/{url.split('/')[-1]})", file=sys.stderr)
- except Exception as e:
- print(f" [{model}] err: {e}", file=sys.stderr)
- print(json.dumps(results, ensure_ascii=False, indent=2))
|