I am using pyttsx3
and speech_recognition
modules and sometimes I receive this error: OSError [Errno -9988] Stream closed
. Here is a little bit same question, but without answer and on Raspberry Pi.
My OS - Windows 10, Python version - 3.8.5
Minimal reproducible example -
import speech_recognition as sr
import pyttsx3
engine = pyttsx3.init()
while True:
r = sr.Recognizer()
print("Say something")
try:
with sr.Microphone() as source:
audio = r.listen(source, phrase_time_limit = 10)
said = ''
try:
said = r.recognize_google(audio, language="en-EN")
except sr.UnknownValueError:
print("Unrecognised speech")
if said == 'hi':
engine.say("Hello there!")
engine.runAndWait()
except OSError as ose:
print(ose)
The full output it produces - I except
ed this error and my output is OSError [Errno -9988] Stream closed
So my question is - How to resolve it???, and why this error appears?