[英]cannot print and listen at the same time
我正在編寫一個基本的說話湯姆之類的代碼,該代碼可以聽人說話並在我希望它顯示講話者所說的文本的一邊重復其音頻。 我面臨的問題是我無法同時使用print和listen命令。 我需要說兩次該短語,一次是在屏幕上打印,另一次是重復。 我想弄清楚這兩種情況都是一次發生的,即,音頻應重復播放並同時顯示,而無需重復兩次該短語。
import speech_recognition
import pyttsx
speech_engine = pyttsx.init()
speech_engine.setProperty('rate', 150)
def speak(text):
speech_engine.say(text)
speech_engine.runAndWait()
recognizer = speech_recognition.Recognizer()
def listen():
with speech_recognition.Microphone() as source:
recognizer.adjust_for_ambient_noise(source)
audio = recognizer.listen(source)
try:
return recognizer.recognize_google(audio)
except speech_recognition.UnknownValueError:
print("Could not understand audio")
except speech_recognition.RequestError as e:
print("Recog Error; {0}".format(e))
return ""
speak("Say something!")
print (listen())
speak("I heard you say " + listen())
speak("Say something!")
text = listen()
speak("I heard you say " + text)
寫:
print(audio)
下:
return recognizer.recognize_google(audio)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.