A
A
Artur01112021-01-02 22:41:09
Python
Artur0111, 2021-01-02 22:41:09

Speech Recognition stops listening to a person, how to fix it?

I make a voice assistant, after the first command it stops working and gives 2 errors:
1 .line 34, in
query2 = r.recognize_google(audio, language='ru-RU')
2. File "C:\Python\Lib\jarwisNew\venv \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

is more interested in the 2nd error. Here is the whole code:

import speech_recognition as sr
import pyttsx3
import pyaudio
import webbrowser

engine=pyttsx3.init()
def record_volume():
r = sr.Recognizer()

with sr.Microphone(device_index = 1) as source:
audio = r.listen(source)

query1 = r.recognize_google(audio, language = 'ru-RU')
(f'{query1.lower()}')

if query1 .lower() == "start" or "download":
engine.say("Hi!")
engine.runAndWait()

if query1.lower() == "how are you":
engine.say('Great!')
engine.runAndWait()

record_volume()

while True:

r = sr.Recognizer()

with sr.Microphone(device_index=1) as source:
audio = r.listen(source)

query2 = r.recognize_google(audio, language='ru -RU')
(f'{query2.lower()}')

if query2.lower() == "start" or "download":
engine.say("Hi!")
engine.runAndWait()

if query2.lower() == "how are you":
engine.say('Great! ')
engine.runAndWait()

PS through while true I wanted to make the program not stop working

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question