I'm using speech recognition to detect certain words. at the moment im just testing but I keep running into an error. I'll insert my code as well as the error I get any help I get is greatly appreciated
File "C:\Users\steph\Desktop\test.py", line 18, in myCommand
command = r.recognize_google(audio)
File "C:\Users\steph\AppData\Local\Programs\Python\Python36-32\lib\site-packages\speech_recognition\__init__.py", line 858, in recognize_google
if not isinstance(actual_result, dict) or len(actual_result.get("alternative", [])) == 0: raise UnknownValueError()
speech_recognition.UnknownValueError
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\steph\Desktop\test.py", line 18, in myCommand
command = r.recognize_google(audio)
File "C:\Users\steph\AppData\Local\Programs\Python\Python36-32\lib\site-packages\speech_recognition\__init__.py", line 858, in recognize_google
if not isinstance(actual_result, dict) or len(actual_result.get("alternative", [])) == 0: raise UnknownValueError()
speech_recognition.UnknownValueError
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\steph\Desktop\test.py", line 29, in <module>
assistant(myCommand())
File "C:\Users\steph\Desktop\test.py", line 22, in myCommand
assistant(myCommand())
File "C:\Users\steph\Desktop\test.py", line 22, in myCommand
assistant(myCommand())
File "C:\Users\steph\Desktop\test.py", line 23, in myCommand
return command
UnboundLocalError: local variable 'command' referenced before assignment
sorry didnt see the error tags
import speech_recognition as sr
from gtts import gTTS
import os
import pyaudio
def talkToMe(audio):
print(audio)
tts=gTTS(text=audio, lang= 'en')
tts.save('audio.mp3')
os.system(r'start C:\Users\steph\Desktop\audio.mp3')
def myCommand():
r = sr.Recognizer()
with sr.Microphone() as source:
print(' I am ready for your next command')
r.pause_threshold = 1
r.adjust_for_ambient_noise(source, duration = 1)
audio = r.listen(source)
try:
command = r.recognize_google(audio)
print('You said: ' + command + '/n')
except sr.UnknownValueError:
assistant(myCommand())
return command
def assistant(a):
if 'time' in a:
talkToMe("lol")
talkToMe('I am ready for your command')
while True:
assistant(myCommand())Traceback (most recent call last):File "C:\Users\steph\Desktop\test.py", line 18, in myCommand
command = r.recognize_google(audio)
File "C:\Users\steph\AppData\Local\Programs\Python\Python36-32\lib\site-packages\speech_recognition\__init__.py", line 858, in recognize_google
if not isinstance(actual_result, dict) or len(actual_result.get("alternative", [])) == 0: raise UnknownValueError()
speech_recognition.UnknownValueError
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\steph\Desktop\test.py", line 18, in myCommand
command = r.recognize_google(audio)
File "C:\Users\steph\AppData\Local\Programs\Python\Python36-32\lib\site-packages\speech_recognition\__init__.py", line 858, in recognize_google
if not isinstance(actual_result, dict) or len(actual_result.get("alternative", [])) == 0: raise UnknownValueError()
speech_recognition.UnknownValueError
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\steph\Desktop\test.py", line 29, in <module>
assistant(myCommand())
File "C:\Users\steph\Desktop\test.py", line 22, in myCommand
assistant(myCommand())
File "C:\Users\steph\Desktop\test.py", line 22, in myCommand
assistant(myCommand())
File "C:\Users\steph\Desktop\test.py", line 23, in myCommand
return command
UnboundLocalError: local variable 'command' referenced before assignment
sorry didnt see the error tags
Error:Traceback (most recent call last):
File "C:\Users\steph\Desktop\test.py", line 18, in myCommand
command = r.recognize_google(audio)
File "C:\Users\steph\AppData\Local\Programs\Python\Python36-32\lib\site-packages\speech_recognition\__init__.py", line 858, in recognize_google
if not isinstance(actual_result, dict) or len(actual_result.get("alternative", [])) == 0: raise UnknownValueError()
speech_recognition.UnknownValueError
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\steph\Desktop\test.py", line 18, in myCommand
command = r.recognize_google(audio)
File "C:\Users\steph\AppData\Local\Programs\Python\Python36-32\lib\site-packages\speech_recognition\__init__.py", line 858, in recognize_google
if not isinstance(actual_result, dict) or len(actual_result.get("alternative", [])) == 0: raise UnknownValueError()
speech_recognition.UnknownValueError
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\steph\Desktop\test.py", line 29, in <module>
assistant(myCommand())
File "C:\Users\steph\Desktop\test.py", line 22, in myCommand
assistant(myCommand())
File "C:\Users\steph\Desktop\test.py", line 22, in myCommand
assistant(myCommand())
File "C:\Users\steph\Desktop\test.py", line 23, in myCommand
return command
UnboundLocalError: local variable 'command' referenced before assignment
