0

I know the version is outdated, but i need to know what the problem is. If i want to run my script, this error appears.

  File "c:/Users/auth/Downloads/JARVIS/JARVIS/jarvis.py", line 319, in <module>
    query = takeCommandMic().lower()
  File "c:/Users/auth/Downloads/JARVIS/JARVIS/jarvis.py", line 118, in takeCommandMic
    with sr.Microphone() as source:
  File "C:\Users\auth\AppData\Roaming\Python\Python36\site-packages\speech_recognition\__init__.py", line 141, in __enter__
    input=True,  # stream is an input stream
  File "C:\Users\auth\AppData\Roaming\Python\Python36\site-packages\pyaudio.py", line 750, in open
    stream = Stream(self, *args, **kwargs)
  File "C:\Users\auth\AppData\Roaming\Python\Python36\site-packages\pyaudio.py", line 441, in __init__
    self._stream = pa.open(**arguments)
OSError: [Errno -9999] Unanticipated host error
Error in sys.excepthook:

Original exception was:

The problems should be there:

def takeCommandMic():
    r = sr.Recognizer()
    with sr.Microphone() as source:
        print("Listening...")
        r.pause_threshold = 0.5
        audio = r.listen(source)
    try:

        print("recognizing...")
        query = r.recognize_google(audio , language="de-DE")
        print(query)
    except Exception as e:
        print(e)
        return "Nichts"
    return query

and also there

if __name__ == "__main__":
    getvoices(1)
    speak("Hallo, hier ist jarvis")
    #wishme()
    
while True:    
    turnOnLightsAtTime()
    query = takeCommandMic().lower()
pbncv
  • 1
  • 1

2 Answers2

0

This would be better suited to a comment, but I do not have the 50 rep required to make one:

It appears you are using the pyaudio library. According to this question: pyaudio-OSError: [Errno -9999] Unanticipated host error (which yours may be equivalent to), this may be caused by not having set the correct permissions to access the microphone.

The method for changing this is OS dependent, but on my Windows device it is under 'Privacy' in Settings.

0

I do not have enough reps to comment and hence posting in answer. Is there any additional stacktrace? For I tried your code and it worked for me. Just that I had to add a couple more functions to make it work for me. Since there are not much details about the TTS you are using, I took the liberty of using pyttsx3, which I am at ease using.

import speech_recognition as sr
import pyttsx3

engine = pyttsx3.init('sapi5')
voices = engine.getProperty('voices')
rate = engine.getProperty('rate')
engine.setProperty('voice', voices[0].id)
engine.setProperty('rate', 150)

def speak(audio):
    engine.say(audio)
    engine.runAndWait()

def takeCommandMic():
    r = sr.Recognizer()
    with sr.Microphone() as source:
        print("Listening...")
        r.pause_threshold = 0.5
        audio = r.listen(source)
    try:

        print("recognizing...")
        query = r.recognize_google(audio , language="de-DE")
        print(query)
    except Exception as e:
        print(e)
        return "Nichts"
    return query


def turnOnLightsAtTime():
    speak("Lights are on. Speak up!")

if __name__ == "__main__":
    speak("Hallo, hier ist jarvis")
    # wishme()

while True:
    turnOnLightsAtTime()
    query = takeCommandMic().lower()
    print("the query is: ", query)
    if 'den' in query:
        speak("yes it is working now")
        print("Yes it is working now")
    elif 'sleep' in query:
        print("the query is: ", query)
        speak("good bye")
        print('good bye!')
        break

Not sure about posting an audio recording here, but for now I am pasting the snapshot that I got. Please know that the print statements are actually spoken up by the voice.

log snapshot

Anand Gautam
  • 2,018
  • 1
  • 3
  • 8
  • Hey, thanks for trying to help. The Thing is: On my Home Computer the (whole) code is working. But at the laptop from school this error is appearing. Do i maybe need administrator perms? – pbncv Jan 05 '22 at 17:01