1
votes

'Here is my code:'

    import speech_recognition as sr  

    # get audio from the microphone                                                                       
    r = sr.Recognizer()                                                                                   
    with sr.Microphone() as source:                                                                       
        print("Please say response:")
        r.adjust_for_ambient_noise(source)                                                                                   
        audio = r.listen(source)   
        resp=r.recognize_google(audio)
    try:
        print("You said " + resp)
    except sr.UnknownValueError:
        print("Could not understand audio")
    except sr.RequestError as e:
        print("Could not request results; {0}".format(e))

'Here is the Error message:'

runfile('C:/Users/Owner/speechrecognition.py', wdir='C:/Users/Owner') Traceback (most recent call last):

File "", line 1, in runfile('C:/Users/Owner/speechrecognition.py', wdir='C:/Users/Owner')

File "C:\Users\Owner\anaconda3\envs\py27\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 827, in runfile execfile(filename, namespace)

File "C:\Users\Owner\anaconda3\envs\py27\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 95, in execfile exec(compile(scripttext, filename, 'exec'), glob, loc)

File "C:/Users/Owner/speechrecognition.py", line 11, in with sr.Microphone() as source:

File "C:\Users\Owner\anaconda3\envs\py27\lib\site-packages\speech_recognition_init_.py", line 141, in enter input=True, # stream is an input stream

File "C:\Users\Owner\anaconda3\envs\py27\lib\site-packages\pyaudio.py", line 750, in open stream = Stream(self, *args, **kwargs)

File "C:\Users\Owner\anaconda3\envs\py27\lib\site-packages\pyaudio.py", line 441, in init self._stream = pa.open(**arguments)

IOError: [Errno -9999] Unanticipated host error

1
Did you allow python to access your mic? New windows versions have access control built into Settings > Privacy > Microphone. Check this. Possible dupe here.B_Dex_Float
Yeah I ran the same code a day before and it was accessing my mic fine, but then when I ran it the next day I started getting this error with PyAudioGia Mancini
I hope one of these helps you ( 1 2 ). If that didn't work, let us know.B_Dex_Float

1 Answers

0
votes

I had alot of issues using pyaudio my self what fixed it for me was pasting this in

if (not os.environ.get('PYTHONHTTPSVERIFY', '') and getattr(ssl, '_create_unverified_context', None)):