mirror of
https://github.com/zhayujie/chatgpt-on-wechat.git
synced 2026-10-25 17:36:29 +08:00
fix: use unique tts output filenames for the remaining voice vendors
Co-authored-by: cowagent <cow@cowagent.ai>
This commit is contained in:
1 parent
8a1c0bc8cf
commit
f5871fbd4e
6 files changed
+12
-10
No files matched your search
@@ -10,7 +10,6 @@ Description:
|
||||
|
||||
import http.client
|
||||
import json
|
||||
import time
|
||||
import requests
|
||||
import datetime
|
||||
import hashlib
|
||||
@@ -51,7 +50,7 @@ def text_to_speech_aliyun(url, text, appkey, token):
|
||||
response = requests.post(url, headers=headers, data=json.dumps(data), timeout=(5, 60), stream=True)
|
||||
|
||||
if response.status_code == 200 and response.headers['Content-Type'] == 'audio/mpeg':
|
||||
output_file = TmpDir().path() + "reply-" + str(int(time.time())) + "-" + str(hash(text) & 0x7FFFFFFF) + ".wav"
|
||||
output_file = TmpDir().path() + "reply-" + uuid.uuid4().hex + ".wav"
|
||||
|
||||
try:
|
||||
save_response(response, output_file, MAX_FILE_BYTES)
|
||||
|
||||
@@ -3,7 +3,7 @@ azure voice service
|
||||
"""
|
||||
import json
|
||||
import os
|
||||
import time
|
||||
import uuid
|
||||
|
||||
import azure.cognitiveservices.speech as speechsdk
|
||||
from langid import classify
|
||||
@@ -81,7 +81,7 @@ class AzureVoice(Voice):
|
||||
else:
|
||||
self.speech_config.speech_synthesis_voice_name = self.config["speech_synthesis_voice_name"]
|
||||
# Avoid the same filename under multithreading
|
||||
fileName = TmpDir().path() + "reply-" + str(int(time.time())) + "-" + str(hash(text) & 0x7FFFFFFF) + ".wav"
|
||||
fileName = TmpDir().path() + "reply-" + uuid.uuid4().hex + ".wav"
|
||||
audio_config = speechsdk.AudioConfig(filename=fileName)
|
||||
speech_synthesizer = speechsdk.SpeechSynthesizer(speech_config=self.speech_config, audio_config=audio_config)
|
||||
result = speech_synthesizer.speak_text(text)
|
||||
|
||||
@@ -6,6 +6,7 @@ import os
|
||||
import time
|
||||
import threading
|
||||
import requests
|
||||
import uuid
|
||||
|
||||
from aip import AipSpeech
|
||||
|
||||
@@ -157,7 +158,7 @@ class BaiduVoice(Voice):
|
||||
# used to be buffered whole by `.content` and written out before
|
||||
# anything could object. `download_to_file` also writes through a temp
|
||||
# file, so an oversized or truncated download leaves nothing behind.
|
||||
fn = TmpDir().path() + f"reply-long-{int(time.time())}-{hash(text)&0x7FFFFFFF}.mp3"
|
||||
fn = TmpDir().path() + f"reply-long-{uuid.uuid4().hex}.mp3"
|
||||
try:
|
||||
download_to_file(audio_url, fn, MAX_FILE_BYTES, timeout=REQUEST_TIMEOUT)
|
||||
except Exception as e:
|
||||
@@ -177,7 +178,7 @@ class BaiduVoice(Voice):
|
||||
{"spd":self.spd, "pit":self.pit, "vol":self.vol, "per":self.per}
|
||||
)
|
||||
if not isinstance(result, dict):
|
||||
fn = TmpDir().path() + f"reply-{int(time.time())}-{hash(text)&0x7FFFFFFF}.mp3"
|
||||
fn = TmpDir().path() + f"reply-{uuid.uuid4().hex}.mp3"
|
||||
with open(fn, "wb") as f:
|
||||
f.write(result)
|
||||
logger.info("[Baidu] 短文本合成 success: %s", fn)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
# Requires: elevenlabs==1.0.3 (pip install elevenlabs==1.0.3)
|
||||
import time
|
||||
import uuid
|
||||
|
||||
from elevenlabs.client import ElevenLabs
|
||||
from elevenlabs import save
|
||||
@@ -22,7 +22,7 @@ class ElevenLabsVoice(Voice):
|
||||
pass
|
||||
|
||||
def textToVoice(self, text):
|
||||
fileName = TmpDir().path() + "reply-" + str(int(time.time())) + "-" + str(hash(text) & 0x7FFFFFFF) + ".mp3"
|
||||
fileName = TmpDir().path() + "reply-" + uuid.uuid4().hex + ".mp3"
|
||||
|
||||
try:
|
||||
audio = client.generate(
|
||||
|
||||
@@ -2,6 +2,7 @@ import json
|
||||
import base64
|
||||
import os
|
||||
import time
|
||||
import uuid
|
||||
from voice.voice import Voice
|
||||
from common.log import logger
|
||||
from tencentcloud.common import credential
|
||||
@@ -105,7 +106,7 @@ class TencentVoice(Voice):
|
||||
response = client.TextToVoice(req)
|
||||
|
||||
if response.Audio:
|
||||
fileName = TmpDir().path() + "reply-" + str(int(time.time())) + "-" + str(hash(text) & 0x7FFFFFFF) + ".mp3"
|
||||
fileName = TmpDir().path() + "reply-" + uuid.uuid4().hex + ".mp3"
|
||||
with open(fileName, "wb") as f:
|
||||
f.write(base64.b64decode(response.Audio))
|
||||
logger.info("[Tencent] textToVoice text={} voice file name={}".format(text, fileName))
|
||||
|
||||
@@ -29,6 +29,7 @@ from voice.voice import Voice
|
||||
from .xunfei_asr import xunfei_asr
|
||||
from .xunfei_tts import xunfei_tts
|
||||
import shutil
|
||||
import uuid
|
||||
|
||||
try:
|
||||
from voice.audio_convert import any_to_mp3
|
||||
@@ -81,7 +82,7 @@ class XunfeiVoice(Voice):
|
||||
def textToVoice(self, text):
|
||||
try:
|
||||
# Avoid the same filename under multithreading
|
||||
fileName = TmpDir().path() + "reply-" + str(int(time.time())) + "-" + str(hash(text) & 0x7FFFFFFF) + ".mp3"
|
||||
fileName = TmpDir().path() + "reply-" + uuid.uuid4().hex + ".mp3"
|
||||
xunfei_tts(self.APPID,self.APIKey,self.APISecret,self.BusinessArgsTTS,text,fileName)
|
||||
logger.info("[Xunfei] textToVoice text={} voice file name={}".format(text, fileName))
|
||||
reply = Reply(ReplyType.VOICE, fileName)
|
||||
|
||||
Reference in new issue
Block a user