From 1f5962c312aedcca004aaa3ad677bdf8f82876bd Mon Sep 17 00:00:00 2001 From: HonestQiao Date: Sun, 23 Feb 2025 10:51:20 +0800 Subject: [PATCH] =?UTF-8?q?=E9=A2=84=E9=98=B2=E7=81=AB=E5=B1=B1=E5=BC=95?= =?UTF-8?q?=E6=93=8E(doubao)=E7=9A=84appid=E5=A1=AB=E5=86=99=E4=B8=BA?= =?UTF-8?q?=E6=95=B4=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/providers/asr/doubao.py | 2 +- core/providers/tts/doubao.py | 17 +++++++++++------ 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/core/providers/asr/doubao.py b/core/providers/asr/doubao.py index 5cbd202fe..561080790 100644 --- a/core/providers/asr/doubao.py +++ b/core/providers/asr/doubao.py @@ -136,7 +136,7 @@ class ASRProvider(ASRProviderBase): """Construct the request payload.""" return { "app": { - "appid": self.appid, + "appid": f"{self.appid}", "cluster": self.cluster, "token": self.access_token, }, diff --git a/core/providers/tts/doubao.py b/core/providers/tts/doubao.py index f6eca9744..74ddde2aa 100644 --- a/core/providers/tts/doubao.py +++ b/core/providers/tts/doubao.py @@ -25,7 +25,7 @@ class TTSProvider(TTSProviderBase): async def text_to_speak(self, text, output_file): request_json = { "app": { - "appid": self.appid, + "appid": f"{self.appid}", "token": "access_token", "cluster": self.cluster }, @@ -49,8 +49,13 @@ class TTSProvider(TTSProviderBase): } } - resp = requests.post(self.api_url, json.dumps(request_json), headers=self.header) - if "data" in resp.json(): - data = resp.json()["data"] - file_to_save = open(output_file, "wb") - file_to_save.write(base64.b64decode(data)) + try: + resp = requests.post(self.api_url, json.dumps(request_json), headers=self.header) + if "data" in resp.json(): + data = resp.json()["data"] + file_to_save = open(output_file, "wb") + file_to_save.write(base64.b64decode(data)) + else: + raise Exception(f"{__name__} status_code: {resp.status_code} response: {resp.content}") + except Exception as e: + raise Exception(f"{__name__} error: {e}")