Voice command keyword listener in Android
Asked Answered
I

1

3

I would like to add voice command listener in my application.Service should listen to predefined keyword and and if keyword is spoken it should call some method.

Voice command recognition (activation command) should work without send request to Google voice servers.

How can I do it on Android?

Thanks for posting some useful resources.

Igloo answered 20/6, 2014 at 7:16 Comment(1)
Without sending to google servers? Then you're looking at finding a 3rd party library that does voice recognition on device. Expect to shell out a good 5 figures for a license, there's only 1 or 2 companies in the world that do that.Tuantuareg
F
4

You can use Pocketsphinx to accomplish this task. Check Pocketsphinx android demo for example how to listen for keyword efficiently in offline and react on the specific commands like a key phrase "oh mighty computer". The code to do that is simple:

you create a recognizer and just add keyword spotting search:

recognizer = SpeechRecognizerSetup.defaultSetup()
        .setAcousticModel(new File(modelsDir, "hmm/en-us-semi"))
        .setDictionary(new File(modelsDir, "lm/cmu07a.dic"))
        .setKeywordThreshold(1e-40f)
        .getRecognizer();

recognizer.addListener(this);
recognizer.addKeyphraseSearch("keywordSearch", "oh mighty computer");
recognizer.startListening("keywordSearch);

and define a listener:

@Override
public void onPartialResult(Hypothesis hypothesis) {
    if (hypothesis == null)
          return;
    String text = hypothesis.getHypstr();
    if (text.equals(KEYPHRASE)) {
      //  do something and restart listening
      recognizer.cancel();
      doSomething();
      recognizer.startListening("keywordSearch");
    }
} 

You can adjust keyword threshold for the best detection/false alarm match. For the ideal detection accuracy keyword should have at least 3 syllables, better 4 syllables.

Fite answered 20/6, 2014 at 7:55 Comment(9)
I downloaded Android project example from official pages, build with using ADT but i obtained following error: "java.io.FileNotFoundException: sync/models/grammar/digit.gram.md5 error." What i doing wrong?Igloo
Probably you do not have ant installed. Make sure that custom build step is executed when you build the project. It must be in project builders list as "Asset List Builder".Fite
I tried follow installation manual from official pages and if i'm trying to build with ANT get following message. workspace/PocketSphinx/build.xml:55: sdk.dir is missing. Make sure to generate local.properties using 'android update project' or to inject it through the ANDROID_HOME environment variable.Igloo
You are doing something wrong. You do not need to build pocketsphinx or pocketsphinx-android at all. Download pocketpshinx-android-demo only, import it into eclipse, build, run.Fite
I have the same filenotfoundexception for each of the asset files in the pocketsphinx project - I'm not building from source. If I rename the files *.md5 I get another filenotfoundexception looking for the original file names w/o the .md5 - did you find a fix for this?Diaster
@jchristof, you should probably provide exception text and describe your situation better, it's easy to find the solution if you follow the guide precisely and provide enough information. If md5 files are not create it means there is something wrong with ant builder. You can check in project properties if ant builder works fine.Fite
I found the reference and see the issue now - i'm importing the project into intellij and the ant custom build doesn't produce the md5s in that build.Diaster
We have a separate setup for android studio, it is mentioned in tutorial. Let me know if you have other issues.Fite
Is there a better way to do it in 2022???Zabrine

© 2022 - 2024 — McMap. All rights reserved.