1
votes

problem screenshot

How to trigger commands after speech to text conversion? Now i have text but unable to compare it using if condition in python so I can perform my required task.I have used pocketsphinx for speech recognition in raspberry pi.

   import os
   from pocketsphinx import LiveSpeech, get_model_path

   model_path = get_model_path()

   speech = LiveSpeech(
        verbose=False,
        sampling_rate=16000,
        buffer_size=2048,
        no_search=False,
        full_utt=False,
        hmm=os.path.join(model_path, 'en-us'),
        lm=os.path.join(model_path, 'en-us.lm.bin'),
        dic=os.path.join(model_path, 'cmudict-en-us.dict')
    )

    for phrase in speech:
       print(phrase)
       if phrase == "HOME"
           print (OK)

Code doesn't give any error and work fine; what i say it prints on the screen i.e. Code works till last 3rd line [print (phrase)] and give expected results but last 2 line doesn't perform required task but give no error

1
What is it prints exactly? Code looks correct except of value of OK (is it variable or you mean 'OK'?), maybe you must take account of case (phrase.lower() == 'home') or check not for exact equality ('home' in phrase.lower(), phrase.lower().startswith('home')) - Sav
Thanks for your consideration; I have attached the result, and i have consider the CASES of word "HOME", whereas by OK i meant a word "OK" not a variable - Hassaan Khan
looking into documentation I've seen what phrase isn't a string. change print(phrase) to print(phrase, type(phrase), dir(phrase)) and show the result, it may hint how to compare it or get a string from it - Sav
Really appreciate your answer; u r right that it's not a string ;when i print (type(phrase)) it shows[<class 'pocketsphinx.LiveSpeech'>] Could u guide me how to compare class and string ; Since I am a NOOB in programming , when i type [dir(phrase)] it shows number of complex directories. - Hassaan Khan

1 Answers

0
votes

You can use

if str(phrase) == "HOME":

or

if phrase.hypothesis() == "HOME":