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

@@ -82,7 +82,8 @@ class BaiduVoice(Voice):
{"spd": self.spd, "pit": self.pit, "vol": self.vol, "per": self.per},
)
if not isinstance(result, dict):
fileName = TmpDir().path() + "reply-" + str(int(time.time())) + ".mp3"
# Avoid the same filename under multithreading
fileName = TmpDir().path() + "reply-" + str(int(time.time())) + "-" + str(hash(text) & 0x7FFFFFFF) + ".mp3"
with open(fileName, "wb") as f:
f.write(result)
logger.info("[Baidu] textToVoice text={} voice file name={}".format(text, fileName))