From 75f094218b36b34b436ee8bdb55be4ac91e1bdbd Mon Sep 17 00:00:00 2001 From: guo zebin Date: Fri, 27 Mar 2026 14:39:28 +0800 Subject: [PATCH] =?UTF-8?q?1.ali=20tts=E8=AF=B7=E6=B1=82=E6=A0=BC=E5=BC=8F?= =?UTF-8?q?=E7=94=B1mp3=E6=94=B9=E4=B8=BAwav=EF=BC=9B2.=E4=BF=AE=E5=A4=8DC?= =?UTF-8?q?ontent-Type=E5=8C=B9=E9=85=8D=E8=BF=87=E4=B8=A5=E5=AF=BC?= =?UTF-8?q?=E8=87=B4=E8=AF=AD=E9=9F=B3=E5=90=88=E6=88=90=E5=A4=B1=E8=B4=A5?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 4.6 --- tts/ali_tss.py | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/tts/ali_tss.py b/tts/ali_tss.py index 81f54a0..baf3281 100644 --- a/tts/ali_tss.py +++ b/tts/ali_tss.py @@ -103,7 +103,7 @@ class Speech: } # text = f"{text}" # 设置HTTPS Body。 - body = {'appkey': self.ali_nls_app_key, 'token': self.token,'speech_rate':0, 'text': text, 'format': 'mp3', 'sample_rate': 16000, 'voice': config_util.config["attribute"]["voice"]} + body = {'appkey': self.ali_nls_app_key, 'token': self.token,'speech_rate':0, 'text': text, 'format': 'wav', 'sample_rate': 16000, 'voice': config_util.config["attribute"]["voice"]} body = json.dumps(body) conn = http.client.HTTPSConnection(host, context=_ssl_context) conn.request(method='POST', url=url, body=body, headers=httpHeaders) @@ -112,13 +112,10 @@ class Speech: tt = time.time() contentType = response.getheader('Content-Type') body = response.read() - if 'audio/mpeg' == contentType : - file_url = './samples/sample-' + str(int(time.time() * 1000)) + '.mp3' - with wave.open(file_url, 'wb') as wf: - wf.setnchannels(1) - wf.setsampwidth(2) - wf.setframerate(16000) - wf.writeframes(body) + if contentType and 'audio' in contentType : + file_url = './samples/sample-' + str(int(time.time() * 1000)) + '.wav' + with open(file_url, 'wb') as f: + f.write(body) else : util.log(1, "[x] 语音转换失败!")