/** * Decode frames until recognition is complete. * * @param referenceText the reference text (or null) * @return a result */ @Override public Result decode(String referenceText) { searchManager.startRecognition(); Result result; do { result = searchManager.recognize(featureBlockSize); if (result != null) { result.setReferenceText(referenceText); fireResultListeners(result); } } while (result != null && !result.isFinal()); searchManager.stopRecognition(); return result; }
public static void main(String[] args) { ConfigurationManager cm; if (args.length > 0) { cm = new ConfigurationManager(args[0]); } else { cm = new ConfigurationManager(Sphinx4see.class.getResource("sphinx4see.config.xml")); } // allocate the recognizer System.out.println("Loading..."); Recognizer recognizer = (Recognizer) cm.lookup("recognizer"); recognizer.allocate(); // start the microphone or exit if the programm if this is not possible Microphone microphone = (Microphone) cm.lookup("microphone"); if (!microphone.startRecording()) { System.out.println("Cannot start microphone."); recognizer.deallocate(); System.exit(1); } printInstructions(); // loop the recognition until the programm exits. while (true) { System.out.println("Start speaking. Press Ctrl-C to quit.\n"); Result result = recognizer.recognize(); if (result != null) { String resultText = result.getBestFinalResultNoFiller(); System.out.println("You said: " + resultText + '\n'); if (resultText == "alone") { System.out.println("Do not be afraid, baby!"); } } else { System.out.println("I can't hear what you said.\n"); } } }
/** * Retrieves the rule parse for the given result * * @param the recognition result * @return the rule parse for the result * @throws GrammarException */ RuleParse getRuleParse(Result result) throws GrammarException { String resultText = result.getBestFinalResultNoFiller(); BaseRecognizer jsapiRecognizer = new BaseRecognizer(getGrammar().getGrammarManager()); try { jsapiRecognizer.allocate(); } catch (EngineException | EngineStateError e) { System.err.println("failed to allocate jsapi recognizer: " + e.getMessage()); } RuleGrammar ruleGrammar = new BaseRuleGrammar(jsapiRecognizer, getGrammar().getRuleGrammar()); RuleParse ruleParse = ruleGrammar.parse(resultText, null); return ruleParse; }
static void processSpeech(SphinxServer server) { ConfigurationManager cm = new ConfigurationManager(PATrecognizerTest.class.getResource(config)); // allocate the recognizer Log.info("Loading..."); Recognizer recognizer = (Recognizer) cm.lookup("recognizer"); recognizer.allocate(); // start the microphone or exit if the programm if this is not possible Microphone microphone = (Microphone) cm.lookup("microphone"); if (!microphone.startRecording()) { Log.severe("Cannot start microphone."); recognizer.deallocate(); System.exit(1); } System.out.println("Sample questions are in PATlm_training_file"); // loop the recognition until the programm exits. while (true) { System.out.println("Start speaking. Press Ctrl-C to quit.\n"); Result result = recognizer.recognize(); if (result != null) { String resultText = result.getBestResultNoFiller(); System.out.println("You said: " + resultText + '\n'); String name = server.getServerId(); String message = work1 + "\"" + resultText + "\"}"; server.execute(message); try { Thread.sleep(4000); } catch (Exception e) { System.out.println(e.toString()); break; } } else { System.out.println("I can't hear what you said."); } } }