Search in sources :

Example 1 with SpeechRecognitionEvent

use of org.eclipse.smarthome.core.voice.SpeechRecognitionEvent in project smarthome by eclipse.

the class DialogProcessor method sttEventReceived.

@Override
public synchronized void sttEventReceived(STTEvent sttEvent) {
    if (sttEvent instanceof SpeechRecognitionEvent) {
        if (false == this.isSTTServerAborting) {
            this.sttServiceHandle.abort();
            this.isSTTServerAborting = true;
            SpeechRecognitionEvent sre = (SpeechRecognitionEvent) sttEvent;
            String question = sre.getTranscript();
            try {
                toggleProcessing(false);
                String answer = hli.interpret(this.locale, question);
                if (answer != null) {
                    say(answer);
                }
            } catch (InterpretationException e) {
                say(e.getMessage());
            }
        }
    } else if (sttEvent instanceof RecognitionStopEvent) {
        toggleProcessing(false);
    } else if (sttEvent instanceof SpeechRecognitionErrorEvent) {
        if (false == this.isSTTServerAborting) {
            this.sttServiceHandle.abort();
            this.isSTTServerAborting = true;
            toggleProcessing(false);
            SpeechRecognitionErrorEvent sre = (SpeechRecognitionErrorEvent) sttEvent;
            say("Encountered error: " + sre.getMessage());
        }
    }
}
Also used : RecognitionStopEvent(org.eclipse.smarthome.core.voice.RecognitionStopEvent) InterpretationException(org.eclipse.smarthome.core.voice.text.InterpretationException) SpeechRecognitionErrorEvent(org.eclipse.smarthome.core.voice.SpeechRecognitionErrorEvent) SpeechRecognitionEvent(org.eclipse.smarthome.core.voice.SpeechRecognitionEvent)

Aggregations

RecognitionStopEvent (org.eclipse.smarthome.core.voice.RecognitionStopEvent)1 SpeechRecognitionErrorEvent (org.eclipse.smarthome.core.voice.SpeechRecognitionErrorEvent)1 SpeechRecognitionEvent (org.eclipse.smarthome.core.voice.SpeechRecognitionEvent)1 InterpretationException (org.eclipse.smarthome.core.voice.text.InterpretationException)1