list-aliyun-voices.py 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #!/usr/bin/env python3
  2. """
  3. list-aliyun-voices.py — 列阿里云百炼 TTS 模型的 voice 池
  4. 按服务分类尝试不同 endpoint
  5. """
  6. import os, sys, json, requests
  7. env_file = "/data/ai/audio/server/.env"
  8. if os.path.exists(env_file):
  9. with open(env_file) as f:
  10. for line in f:
  11. if line.startswith("DASHSCOPE_API_KEY="):
  12. api_key = line.split("=", 1)[1].strip()
  13. break
  14. else:
  15. api_key = os.environ.get("DASHSCOPE_API_KEY", "")
  16. if not api_key:
  17. print("ERROR: DASHSCOPE_API_KEY not set", file=sys.stderr)
  18. sys.exit(1)
  19. # 每个模型的 url + voices 路径
  20. configs = [
  21. ("cosyvoice-v3-flash", "https://dashscope.aliyuncs.com/api/v1/services/audio/tts/SpeechSynthesizer/voices", {"model": "cosyvoice-v3-flash"}),
  22. ("cosyvoice-v2", "https://dashscope.aliyuncs.com/api/v1/services/audio/tts/SpeechSynthesizer/voices", {"model": "cosyvoice-v2"}),
  23. ("cosyvoice-v1", "https://dashscope.aliyuncs.com/api/v1/services/audio/tts/SpeechSynthesizer/voices", {"model": "cosyvoice-v1"}),
  24. ("qwen3-tts-instruct-flash", "https://dashscope.aliyuncs.com/api/v1/services/aigc/multimodal-generation/voices", {"model": "qwen3-tts-instruct-flash"}),
  25. ("qwen3-tts-flash", "https://dashscope.aliyuncs.com/api/v1/services/aigc/multimodal-generation/voices", {"model": "qwen3-tts-flash"}),
  26. ("sambert-zhichu-v1", "https://dashscope.aliyuncs.com/api/v1/services/audio/tts/SpeechSynthesizer/voices", {"model": "sambert-zhichu-v1"}),
  27. ]
  28. results = {} # model -> [voices]
  29. for model, url, payload in configs:
  30. try:
  31. r = requests.post(url, headers={
  32. "Authorization": f"Bearer {api_key}",
  33. "Content-Type": "application/json",
  34. }, json=payload, timeout=15)
  35. d = r.json()
  36. if d.get("code"):
  37. print(f" [{model}] skip: {d.get('message')[:80]}", file=sys.stderr)
  38. continue
  39. # 不同的返回结构都试
  40. voices = (
  41. d.get("output", {}).get("voices")
  42. or d.get("output", {}).get("voice_list")
  43. or d.get("output", {}).get("data")
  44. or []
  45. )
  46. results[model] = voices
  47. print(f" [{model}] ok: {len(voices)} voices (url: {url.split('/')[-2]}/{url.split('/')[-1]})", file=sys.stderr)
  48. except Exception as e:
  49. print(f" [{model}] err: {e}", file=sys.stderr)
  50. print(json.dumps(results, ensure_ascii=False, indent=2))