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

@@ -79,7 +79,8 @@ class AzureVoice(Voice):
self.speech_config.speech_synthesis_voice_name = self.config["speech_synthesis_voice_name"]
else:
self.speech_config.speech_synthesis_voice_name = self.config["speech_synthesis_voice_name"]
fileName = TmpDir().path() + "reply-" + str(int(time.time())) + ".wav"
# Avoid the same filename under multithreading
fileName = TmpDir().path() + "reply-" + str(int(time.time())) + "-" + str(hash(text) & 0x7FFFFFFF) + ".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)