fix: 四个TTS引擎添加友好中文错误提示(欠费/密钥无效/频率限制)
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -35,8 +35,14 @@ def synthesize_cosyvoice(text, speed=1.0, pitch=0, volume=1.0, instruction=None)
|
||||
|
||||
response = requests.post(url, json=payload, headers=headers, timeout=60)
|
||||
|
||||
if response.status_code == 402 or response.status_code == 403:
|
||||
raise Exception('CosyVoice 账户欠费或权限不足,请联系管理员')
|
||||
if response.status_code == 401:
|
||||
raise Exception('CosyVoice API密钥无效,请联系管理员')
|
||||
if response.status_code == 429:
|
||||
raise Exception('CosyVoice 请求过于频繁,请稍后再试')
|
||||
if response.status_code != 200:
|
||||
raise Exception(f'CosyVoice API错误: {response.status_code} - {response.text}')
|
||||
raise Exception(f'CosyVoice 服务异常({response.status_code}),请稍后再试')
|
||||
|
||||
result = response.json()
|
||||
|
||||
|
||||
@@ -42,8 +42,14 @@ def synthesize_doubao(text, speed=1.0, pitch=0, volume=1.0, emotion='neutral'):
|
||||
|
||||
response = requests.post(url, json=payload, headers=headers, timeout=60)
|
||||
|
||||
if response.status_code == 402 or response.status_code == 403:
|
||||
raise Exception('豆包 账户欠费或权限不足,请联系管理员')
|
||||
if response.status_code == 401:
|
||||
raise Exception('豆包 API密钥无效,请联系管理员')
|
||||
if response.status_code == 429:
|
||||
raise Exception('豆包 请求过于频繁,请稍后再试')
|
||||
if response.status_code != 200:
|
||||
raise Exception(f'豆包API错误: {response.status_code} - {response.text}')
|
||||
raise Exception(f'豆包 服务异常({response.status_code}),请稍后再试')
|
||||
|
||||
result = response.json()
|
||||
|
||||
|
||||
@@ -43,11 +43,17 @@ def synthesize_fish_audio(text, speed=1.0, pitch=0, volume=1.0, emotion='neutral
|
||||
auth=(PROXY_USER, PROXY_PASS), timeout=120
|
||||
)
|
||||
|
||||
if response.status_code == 402:
|
||||
raise Exception('Fish Audio 余额不足,请联系管理员充值')
|
||||
if response.status_code == 401:
|
||||
raise Exception('Fish Audio API密钥无效,请联系管理员')
|
||||
if response.status_code == 429:
|
||||
raise Exception('Fish Audio 请求过于频繁,请稍后再试')
|
||||
if response.status_code != 200:
|
||||
raise Exception(f'Fish Audio API错误: {response.status_code} - {response.text[:200]}')
|
||||
raise Exception(f'Fish Audio 服务异常({response.status_code}),请稍后再试')
|
||||
|
||||
audio_bytes = response.content
|
||||
if not audio_bytes:
|
||||
raise Exception('Fish Audio返回空音频')
|
||||
raise Exception('Fish Audio 返回空音频,请稍后再试')
|
||||
|
||||
return audio_bytes
|
||||
|
||||
@@ -38,8 +38,14 @@ def synthesize_minimax(text, speed=1.0, pitch=0, volume=1.0, emotion='neutral'):
|
||||
|
||||
response = requests.post(url, json=payload, headers=headers, timeout=60)
|
||||
|
||||
if response.status_code == 402:
|
||||
raise Exception('MiniMax 余额不足,请联系管理员充值')
|
||||
if response.status_code == 401 or response.status_code == 403:
|
||||
raise Exception('MiniMax API密钥无效,请联系管理员')
|
||||
if response.status_code == 429:
|
||||
raise Exception('MiniMax 请求过于频繁,请稍后再试')
|
||||
if response.status_code != 200:
|
||||
raise Exception(f'MiniMax API错误: {response.status_code} - {response.text}')
|
||||
raise Exception(f'MiniMax 服务异常({response.status_code}),请稍后再试')
|
||||
|
||||
result = response.json()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user