如何修复 "BaseException is not allowed"

How to fix "BaseException is not allowed"

我试图让这个脚本得到我所说的并在终端上打印出来,但我收到这个错误

TypeError: catching classes that do not inherit from BaseException is not allowed

为此,我遵循了一个教程,他在 运行 版本 3.9.5 中工作得很好我已经尝试查找它,但我发现没有任何帮助,如果你知道请告诉我

 import speech_recognition
    import pyttsx3
    
    recognizer = speech_recognition.Recognizer()
    
    while True:
        try:
            with speech_recognition.Microphone() as mic:
                recognizer.adjust_for_ambient_noise(mic, duration=0.2)
                audio = recognizer.listen(mic)
    
                text = recognizer.recognize_google(audio)
                text = text.lower()
    
                print(f"Recognized {text}")
    
        except speech_recognition.UnknownValueError():
            recognizer = speech_recognition.Recognizer()
            continue

你的

except speech_recognition.UnknownValueError():

应该是

except speech_recognition.UnknownValueError:

即它应该命名类型,而不是调用它并使用 return 值。