Merge branch 'doubao-asr' of https://github.com/xinnan-tech/xiaozhi-esp32-server into doubao-asr

This commit is contained in:
hrz 2025-02-23 12:11:12 +08:00
commit 6282856534
2 changed files with 12 additions and 7 deletions

View file

@ -136,7 +136,7 @@ class ASRProvider(ASRProviderBase):
"""Construct the request payload.""" """Construct the request payload."""
return { return {
"app": { "app": {
"appid": self.appid, "appid": f"{self.appid}",
"cluster": self.cluster, "cluster": self.cluster,
"token": self.access_token, "token": self.access_token,
}, },

View file

@ -25,7 +25,7 @@ class TTSProvider(TTSProviderBase):
async def text_to_speak(self, text, output_file): async def text_to_speak(self, text, output_file):
request_json = { request_json = {
"app": { "app": {
"appid": self.appid, "appid": f"{self.appid}",
"token": "access_token", "token": "access_token",
"cluster": self.cluster "cluster": self.cluster
}, },
@ -49,8 +49,13 @@ class TTSProvider(TTSProviderBase):
} }
} }
resp = requests.post(self.api_url, json.dumps(request_json), headers=self.header) try:
if "data" in resp.json(): resp = requests.post(self.api_url, json.dumps(request_json), headers=self.header)
data = resp.json()["data"] if "data" in resp.json():
file_to_save = open(output_file, "wb") data = resp.json()["data"]
file_to_save.write(base64.b64decode(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}")