pythonspeech-recognitionpocketsphinx

Controlling after Speech Recognition


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


Solution

  • You can use

    if str(phrase) == "HOME":
    

    or

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