Reputation: 53
I am make a simple speech recognition program that will enable me to control my robot with voice command. I only want the program to look for certain words and be relatively fast. My project is based on Micheal Reeves 'I made a robot that shines a laser in my eye' and am trying to create something similar to the voice commands seen in his video.
The issue I am having is that sphinx is fast, but (EDIT: NOT ACCURATE). As well as this, when I enable keywords, the out goes weird. If I say command shutdown, the output will be :
"three nine one four five eight two one eight nine three four two six zero eight nine two one six four eight seven one three four nine five eight two eight
four five nine three one two eight six nine three five seven two zero one nine five eight two four four nine one five eight three two six four two zero seven one nine three four five eight two five one three four eight two six eight zero one three four five two seven eight eight three nine five two four eight one two eight two eight two eight command shutdown command eight one four three eight two two eight "
I am not sure to fix this and I tried to do recognise_google but and it was much more accurate but really slow and i want the keywords enabled so that it only checks if a said a collection of words and then prints it the the screen if i did.
The other issue I am having is with the listen_in_background() function. I cant seem to get it working properly.
Here is my code:
import speech_recognition as sr
import pocketsphinx
keywords = [
("command", 1),
("one", 0),
("two", 0),
("three", 0),
("four", 0),
("five", 0),
("six", 0),
("seven", 0),
("eight", 0),
("nine", 0),
("zero", 0),
("command x axis add", 0),
("command y axis add", 0),
("command x axis subtract", 0),
("command y axis subtract", 0),
("command clear shift string", 0),
("command shutdown", 0),
("command flip tracking", 0),
("command pause", 0),
("command detect face", 0),
("command detect body", 0)
]
def speech2text():
r = sr.Recognizer()
with sr.Microphone() as source:
r.adjust_for_ambient_noise(source)
audio = r.listen(source) #this is were i want to listen in the background to run it at the same
#time as other code
try:
data = r.recognize_sphinx(audio, keyword_entries = keywords)
return data
except:
return "Error..."
while True:
print(speech2text())
Upvotes: 3
Views: 3504
Reputation: 1
I had the same issue. I tried different sensitivities from 0 to 1 and found that if all keywords have a sensitivity of over 0.9, they recognize equally and reasonably accurately and don't randomly spam the output phrase. If the value is any lower than that it spits way too many keywords than is reasonable.
I also got an UnknownValueError when ANY word that wasn't a keyword. If you're looking for a way to only detect those keywords, I'd definitely try setting their sensitivities all to 1 and seeing where that gets you. I think the only downside might be that if words in the keyword list are similar than you might get different hits than you'd expect.
Upvotes: 0