Speech Recognition detect specific word using python

799 Views Asked by At

I am working on a voice assistant project and using SpeechRecognition library to recognise user's commands. I decided to name my assistant ODI and realised that this is not recognised by the SpeechRecognition library. "ODI" keyword is being recognised as "body" or "audi". I was wondering if there is a way to do this?

I want it to listen continuously to the user and once "ODI" word is used, then the recogniser will start recognising other commands.

EDIT: I installed pocketsphinx to detect the keyword in speech and then transfer it to google recognizer once the keyword is matched. I tried both ways, by using r.recognizer_sphinx(keyphrase=[('ode', 1)]) and LiveSpeech(keyword='ode') including threshold values 1e+20 and 1e-40. Both methods don't seem to be working and once I provide the keyphrase argument, it interprets everything with the keyword.

Here is the code snippet:

def get_user_input(self):
    with self.microphone as source:
        self.recognizer.adjust_for_ambient_noise(source, duration=1)
        print("listening")
        audio = self.recognizer.listen(source)

        try:
            transcript = self.recognizer.recognize_sphinx(audio, language='en-us', keyword_entries=[('ode', 1)]).lower()
            print("User said: {0}".format(transcript))
            time.sleep(1)
        except sr.UnknownValueError:
            transcript = ''
            print('Unable to recognize speech')
        except sr.RequestError:
            transcript = ''
            print("Request failed")
        except Exception as e:
            print("Repeat Command", e)
            return "None"
        if "ode" in transcript:
            new_transcript = self.recognizer.recognize_google(audio, language='en-ie').lower()
            return new_transcript

The reason why have 'ode' instead of 'odi' is the CMU dictionary has 'ode' which sounds but the problem is that it keeps detecting other words as 'ode' too. Any help will be appreciated, Thanks!

0

There are 0 best solutions below