private synchronized void doRecognize( final Recognizer.Listener callback, int endOfSpeechRecognitionMode, boolean isNoStartPrompt, boolean isNoStopPrompt) { // "singleton" recognition: only one recognition process at a time is allowed // --> ensure all previous processes are stopped. if (_currentRecognitionHandler != null && _currentRecognizer != null) { _currentRecognizer.cancel(); } _currentRecognitionHandler = callback; _currentRecognizer = _speechKit.createRecognizer( Recognizer.RecognizerType.Dictation, endOfSpeechRecognitionMode, _currentLanguage, _recognitionListener, _handler); if (isNoStartPrompt) { _currentRecognizer.setPrompt(Recognizer.PromptType.RECORDING_START, null); } if (isNoStopPrompt) { _currentRecognizer.setPrompt(Recognizer.PromptType.RECORDING_STOP, null); } _currentRecognizer.start(); }
public void stopRecording(final Recognizer.Listener callback) { try { if (callback != null) { // TODO cancel _currentRecognitionHandler, if it already exists? should it be a list? _currentRecognitionHandler = callback; } _currentRecognizer.stopRecording(); Log.d(PLUGIN_NAME, "stopRecording: stopped recording"); } catch (Exception e) { Log.e(PLUGIN_NAME, "Error while trying to stop recognizing.", e); } }
public void cancelRecognition() { if (_currentRecognizer != null) _currentRecognizer.cancel(); }