Я пытаюсь реализовать распознавание речи и ответ в python в школьном проекте.Не могу понять, что не так с моим кодом:
Код: (импорт speech_recognition as sr
)
def takeCommand():
# It takes microphones recognition from the user and returns String output
r = sr.Recognizer()
with sr.Microphone() as source:
print("Listening...")
r.pause_threshold = 0.8
audio = r.listen(source)
try:
print("Recognizing...")
query = r.recognize_google(audio,language='en-in')
print(f"User said:{query}\n")
except Exception as e:
# print(e)
print("Say that again please")
return "None"
return query
Останавливает ответ после print('Listening...')
оператора.
Traceback(При прерывании клавиатуры):
Listening...
Traceback (most recent call last):
File "c:/Users/Yash Khandelwal/Desktop/Python_Files/Jarvis/Jarvis_Project.py", line 51, in <module>
takeCommand()
File "c:/Users/Yash Khandelwal/Desktop/Python_Files/Jarvis/Jarvis_Project.py", line 36, in takeCommand
audio = r.listen(source)
File "C:\Users\New User\AppData\Local\Programs\Python\Python37\lib\site-packages\speech_recognition\__init__.py", line 652, in listen
buffer = source.stream.read(source.CHUNK)
File "C:\Users\New User\AppData\Local\Programs\Python\Python37\lib\site-packages\speech_recognition\__init__.py", line 161, in read
return self.pyaudio_stream.read(size, exception_on_overflow=False)
File "C:\Users\New User\AppData\Local\Programs\Python\Python37\lib\site-packages\pyaudio.py", line 608, in read
return pa.read_stream(self._stream, num_frames, exception_on_overflow)
KeyboardInterrupt
Это легко решаемо?