From 3503c0f5e4eea8689b55c18bc6cc2b7d11755d50 Mon Sep 17 00:00:00 2001 From: lanhao Date: Fri, 3 Jul 2026 00:23:55 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=9B=9B=E4=B8=AATTS=E5=BC=95=E6=93=8E?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=8F=8B=E5=A5=BD=E4=B8=AD=E6=96=87=E9=94=99?= =?UTF-8?q?=E8=AF=AF=E6=8F=90=E7=A4=BA=EF=BC=88=E6=AC=A0=E8=B4=B9/?= =?UTF-8?q?=E5=AF=86=E9=92=A5=E6=97=A0=E6=95=88/=E9=A2=91=E7=8E=87?= =?UTF-8?q?=E9=99=90=E5=88=B6=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 4.6 --- backend/app/services/cosyvoice_service.py | 8 +++++++- backend/app/services/doubao_service.py | 8 +++++++- backend/app/services/fish_audio_service.py | 10 ++++++++-- backend/app/services/minimax_service.py | 8 +++++++- 4 files changed, 29 insertions(+), 5 deletions(-) diff --git a/backend/app/services/cosyvoice_service.py b/backend/app/services/cosyvoice_service.py index 3685493..4d6b6a3 100644 --- a/backend/app/services/cosyvoice_service.py +++ b/backend/app/services/cosyvoice_service.py @@ -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() diff --git a/backend/app/services/doubao_service.py b/backend/app/services/doubao_service.py index b57d433..12c56b2 100644 --- a/backend/app/services/doubao_service.py +++ b/backend/app/services/doubao_service.py @@ -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() diff --git a/backend/app/services/fish_audio_service.py b/backend/app/services/fish_audio_service.py index f97a821..908bc60 100644 --- a/backend/app/services/fish_audio_service.py +++ b/backend/app/services/fish_audio_service.py @@ -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 diff --git a/backend/app/services/minimax_service.py b/backend/app/services/minimax_service.py index 6d5f8e7..21b2c87 100644 --- a/backend/app/services/minimax_service.py +++ b/backend/app/services/minimax_service.py @@ -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()