private void setupRecognizer(File assetsDir) { try { recognizer = defaultSetup() .setAcousticModel(new File(assetsDir, "en-us-ptm")) .setDictionary(new File(assetsDir, "cmudict-en-us.dict")) // .setRawLogDir(assetsDir) // To disable logging of raw audio comment out this call // (takes a lot of space on the device) .setKeywordThreshold( 1e-45f) // Threshold to tune for keyphrase to balance between false alarms and // misses .setBoolean("-allphone_ci", true) .getRecognizer(); recognizer.addListener(this); // Create keyword-activation search. recognizer.addKeyphraseSearch(KWS_SEARCH, KEYPHRASE); } catch (Exception e) { e.printStackTrace(); } }
/** * The recognizer can be configured to perform multiple searches of different kind and switch * between them. * * <p>THE HEART OF THE APP! * * @param assetsDir * @throws IOException */ private void setupRecognizer(File assetsDir) throws IOException { recognizer = defaultSetup() .setAcousticModel(new File(assetsDir, "en-us-ptm")) // Acoustic model .setDictionary( new File( assetsDir, "cmudict-en-us.dict")) // English dictionary of most common words .setRawLogDir( assetsDir) // To disable logging of raw audio comment out this call (takes a lot of // space on the device) .setKeywordThreshold( 1e-15f) // Threshold to tune for keyphrase to balance between false alarms and // misses // .setBoolean("-allphone_ci", true) // Use // context-independent phonetic search, context-dependent is too slow for mobile .getRecognizer(); recognizer.addListener(this); // Create keyword-activation search. recognizer.addKeyphraseSearch(KWS_SEARCH, KEYPHRASE); File animalGrammar = new File(assetsDir, "animals.gram"); recognizer.addKeywordSearch("animals", animalGrammar); }