Jsapi20SpokenInput implements SpokenInput, RecognizerListener { @Override public void startRecognition( final DataModel model, final SpeechRecognizerProperties speech, final DtmfRecognizerProperties dtmf) throws NoresourceError, BadFetchError { if (recognizer == null) { throw new NoresourceError("recognizer not available"); } if (speech != null) { final RecognizerProperties recProbs = recognizer .getRecognizerProperties(); final float confidence = speech.getConfidencelevel(); final int scaledConfidence = scale(confidence, RecognizerProperties.MIN_CONFIDENCE, RecognizerProperties.MAX_CONFIDENCE); recProbs.setConfidenceThreshold(scaledConfidence); final float sensitivity = speech.getSensitivity(); final int scaledSensitivity = scale(sensitivity, RecognizerProperties.MIN_SENSITIVITY, RecognizerProperties.MAX_SENSITIVITY); recProbs.setSensitivity(scaledSensitivity); final float speedVsAccuracs = speech.getSpeedvsaccuracy(); final int scaledSpeedVsAccuracy = scale(speedVsAccuracs, RecognizerProperties.MIN_ACCURACY, RecognizerProperties.MAX_ACCURACY); recProbs.setSensitivity(scaledSpeedVsAccuracy); final long completeTimeout = speech.getCompletetimeoutAsMsec(); recProbs.setCompleteTimeout((int) completeTimeout); final long incompleteTimeout = speech.getCompletetimeoutAsMsec(); recProbs.setIncompleteTimeout((int) incompleteTimeout); } if (LOGGER.isDebugEnabled()) { LOGGER.debug("starting recognition..."); } currentResultListener = new JVoiceXMLResultListener(this); recognizer.addResultListener(currentResultListener); recognizer.requestFocus(); try { recognizer.waitEngineState(Recognizer.FOCUSED); recognizer.resume(); recognizer.waitEngineState(Recognizer.RESUMED); } catch (EngineStateException e) { throw new NoresourceError(e.getMessage(), e); } catch (IllegalArgumentException e) { throw new NoresourceError(e.getMessage(), e); } catch (IllegalStateException e) { throw new NoresourceError(e.getMessage(), e); } catch (InterruptedException e) { throw new NoresourceError(e.getMessage(), e); } final SpokenInputEvent event = new RecognitionStartedEvent(this, null); fireInputEvent(event); if (LOGGER.isDebugEnabled()) { LOGGER.debug("...recognition started"); } } Jsapi20SpokenInput(final RecognizerMode defaultDescriptor,
            final InputMediaLocatorFactory mediaLocatorFactory); void setMediaLocator(final URI locator); @Override void open(); @Override void close(); @Override void addListener(final SpokenInputListener inputListener); @Override void removeListener(final SpokenInputListener inputListener); @Override Collection<BargeInType> getSupportedBargeInTypes(); @Override GrammarImplementation<RuleGrammar> loadGrammar(final URI uri,
            final GrammarType grammarType); @Override void activateGrammars(
            final Collection<GrammarImplementation<? extends Object>> grammars); @Override void deactivateGrammars(
            final Collection<GrammarImplementation<? extends Object>> grammars); @Override void startRecognition(
            final DataModel model,
            final SpeechRecognizerProperties speech,
            final DtmfRecognizerProperties dtmf); @Override void stopRecognition(); @Override void activate(); @Override void passivate(); @Override void connect(final ConnectionInformation info); @Override void disconnect(final ConnectionInformation info); @Override String getType(); void setType(final String resourceType); @Override Collection<GrammarType> getSupportedGrammarTypes(); @Override boolean isBusy(); @Override void recognizerUpdate(final RecognizerEvent recognizerEvent);  }
@Test(timeout = 4000) public void testStartRecognition() throws Exception, JVoiceXMLEvent { final SrgsXmlDocument document = new SrgsXmlDocument(); final Grammar grammar = document.getGrammar(); grammar.setXmlLang(Locale.US); final Rule rule = grammar.appendChild(Rule.class); rule.makePublic(); rule.setId("root"); grammar.setRoot(rule); rule.addText("test"); final String xml = document.toString(); final File file = File.createTempFile("jvxmltest", "srgs"); final URI uri = writeToFile(file, xml); final GrammarImplementation<?> impl = input.loadGrammar(uri, GrammarType.SRGS_XML); final Collection<GrammarImplementation<?>> implementations = new java.util.ArrayList<GrammarImplementation<?>>(); implementations.add(impl); input.activateGrammars(implementations); input.startRecognition(null, null, null); synchronized (monitor) { monitor.wait(); } }