我正在Raspberry Pi 4上使用Python编写虚拟助手程序(使用Thonny),但遇到了上述错误。我的程序相对简单,但是我无法理解为什么在运行该程序大约30分钟后错误仍然弹出。我的代码如下:
def speak(text):
text = ("<prosody rate='+0.20'><prosody volume='loud'>" + text + "</prosody>")
subprocess.call(['swift', '-o', '/home/pi/response', text], shell=False)
os.system('aplay /home/pi/response')
def greeting():
hour = int(datetime.datetime.now().hour)
if hour >= 0 and hour < 12:
speak("Initializing... Starting program. I am on line. Good morning.")
elif hour >= 12 and hour < 18:
speak("Initializing... Starting program. I am on line. Good afternoon.")
else:
speak("Initializing... Starting program. I am on line. Good evening.")
def listen_wakeWord():
r = sr.Recognizer()
with sr.Microphone() as source:
print("Listening...")
r.adjust_for_ambient_noise(source, duration=0.1)
audio = r.listen(source, phrase_time_limit=7)
try:
data = r.recognize_google(audio, language='en-US')
print(f"You said: {data}\n")
except Exception as e:
#print(e)
print("Input Not Recognized...")
greeting()
while True:
try:
listen_wakeWord()
except Exception as e:
print(e)