首页 > 解决方案 > Errno 24 打开的文件太多

问题描述

我正在Raspberry Pi 4(使用Thonny)上用Python编写一个虚拟助手程序,我遇到了上述错误。我的程序相对简单,但我无法理解为什么在运行程序大约 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)

标签: python-3.x

解决方案


推荐阅读