我一直在寻找一种解决方案,我一直在使用pyttsx3模块进行文本转语音,但无法使用语音识别或键盘中断来停止engine.say()和engine.runandwait()。在阅读消息时,我们无法在中间中断engine.say()。你的帮助是高度赞赏的。
def textToSpeechInitialization():
text2speech = pyttsx3.init()
rate = text2speech.getProperty('rate')
volume = text2speech.getProperty('volume')
voices = text2speech.getProperty('voice')
text2speech.setProperty('rate', 140)
text2speech.setProperty('volume',1)
return text2speech
def textToSpeechOutput(msg):
print(msg)
text2speech.say(msg)
text2speech.runAndWait()
if __name__ == '__main__':
global text2speech
text2speech = textToSpeechInitialization()
msg = "Hello how are you doing. How many years you have been working in this orgranisation"
textToSpeechOutput(msg)