fix: Avoid the same filename under multithreading (#933)

This commit is contained in:
JS00000
2023-04-23 23:56:32 +08:00
committed by GitHub
parent d6a4b35cd3
commit dca5c058e0
4 changed files with 7 additions and 4 deletions

View File

@@ -35,7 +35,8 @@ class GoogleVoice(Voice):
def textToVoice(self, text):
try:
mp3File = TmpDir().path() + "reply-" + str(int(time.time())) + ".mp3"
# Avoid the same filename under multithreading
mp3File = TmpDir().path() + "reply-" + str(int(time.time())) + "-" + str(hash(text) & 0x7FFFFFFF) + ".mp3"
tts = gTTS(text=text, lang="zh")
tts.save(mp3File)
logger.info("[Google] textToVoice text={} voice file name={}".format(text, mp3File))