diff --git a/bundles/org.openhab.voice.googlestt/src/main/java/org/openhab/voice/googlestt/internal/GoogleSTTService.java b/bundles/org.openhab.voice.googlestt/src/main/java/org/openhab/voice/googlestt/internal/GoogleSTTService.java index a217c6a4170..d3eca88a0d1 100644 --- a/bundles/org.openhab.voice.googlestt/src/main/java/org/openhab/voice/googlestt/internal/GoogleSTTService.java +++ b/bundles/org.openhab.voice.googlestt/src/main/java/org/openhab/voice/googlestt/internal/GoogleSTTService.java @@ -405,10 +405,8 @@ public class GoogleSTTService implements STTService { String transcript = transcriptBuilder.toString(); if (!transcript.isBlank()) { sttListener.sttEventReceived(new SpeechRecognitionEvent(transcript, averageConfidence)); - } else if (!config.noResultsMessage.isBlank()) { - sttListener.sttEventReceived(new SpeechRecognitionErrorEvent(config.noResultsMessage)); } else { - sttListener.sttEventReceived(new SpeechRecognitionErrorEvent("No results")); + sttListener.sttEventReceived(new SpeechRecognitionErrorEvent(config.noResultsMessage)); } } } @@ -418,13 +416,7 @@ public class GoogleSTTService implements STTService { logger.warn("Recognition error: ", t); if (!aborted.getAndSet(true)) { sttListener.sttEventReceived(new RecognitionStopEvent()); - if (!config.errorMessage.isBlank()) { - sttListener.sttEventReceived(new SpeechRecognitionErrorEvent(config.errorMessage)); - } else { - String errorMessage = t.getMessage(); - sttListener.sttEventReceived( - new SpeechRecognitionErrorEvent(errorMessage != null ? errorMessage : "Unknown error")); - } + sttListener.sttEventReceived(new SpeechRecognitionErrorEvent(config.errorMessage)); } } diff --git a/bundles/org.openhab.voice.voskstt/src/main/java/org/openhab/voice/voskstt/internal/VoskSTTService.java b/bundles/org.openhab.voice.voskstt/src/main/java/org/openhab/voice/voskstt/internal/VoskSTTService.java index b4d38392140..121655b9e42 100644 --- a/bundles/org.openhab.voice.voskstt/src/main/java/org/openhab/voice/voskstt/internal/VoskSTTService.java +++ b/bundles/org.openhab.voice.voskstt/src/main/java/org/openhab/voice/voskstt/internal/VoskSTTService.java @@ -271,27 +271,15 @@ public class VoskSTTService implements STTService { if (!transcript.isBlank()) { sttListener.sttEventReceived(new SpeechRecognitionEvent(transcript, 1F)); } else { - if (!config.noResultsMessage.isBlank()) { - sttListener.sttEventReceived(new SpeechRecognitionErrorEvent(config.noResultsMessage)); - } else { - sttListener.sttEventReceived(new SpeechRecognitionErrorEvent("No results")); - } + sttListener.sttEventReceived(new SpeechRecognitionErrorEvent(config.noResultsMessage)); } } } catch (IOException e) { logger.warn("Error running speech to text: {}", e.getMessage()); - if (config.errorMessage.isBlank()) { - sttListener.sttEventReceived(new SpeechRecognitionErrorEvent("Error")); - } else { - sttListener.sttEventReceived(new SpeechRecognitionErrorEvent(config.errorMessage)); - } + sttListener.sttEventReceived(new SpeechRecognitionErrorEvent(config.errorMessage)); } catch (UnsatisfiedLinkError e) { logger.warn("Missing native dependency: {}", e.getMessage()); - if (config.errorMessage.isBlank()) { - sttListener.sttEventReceived(new SpeechRecognitionErrorEvent("Error")); - } else { - sttListener.sttEventReceived(new SpeechRecognitionErrorEvent(config.errorMessage)); - } + sttListener.sttEventReceived(new SpeechRecognitionErrorEvent(config.errorMessage)); } finally { if (recognizer != null) { recognizer.close(); diff --git a/bundles/org.openhab.voice.watsonstt/README.md b/bundles/org.openhab.voice.watsonstt/README.md index 46ba04c50e0..c9610b56cc1 100644 --- a/bundles/org.openhab.voice.watsonstt/README.md +++ b/bundles/org.openhab.voice.watsonstt/README.md @@ -51,6 +51,7 @@ org.openhab.voice.watsonstt:optOutLogging=false org.openhab.voice.watsonstt:smartFormatting=false org.openhab.voice.watsonstt:redaction=false org.openhab.voice.watsonstt:noResultsMessage="Sorry, I didn't understand you" +org.openhab.voice.watsonstt:errorMessage="Sorry, something went wrong" ``` ### Default Speech-to-Text Configuration diff --git a/bundles/org.openhab.voice.watsonstt/src/main/java/org/openhab/voice/watsonstt/internal/WatsonSTTConfiguration.java b/bundles/org.openhab.voice.watsonstt/src/main/java/org/openhab/voice/watsonstt/internal/WatsonSTTConfiguration.java index ca5a089126d..818cc6f228a 100644 --- a/bundles/org.openhab.voice.watsonstt/src/main/java/org/openhab/voice/watsonstt/internal/WatsonSTTConfiguration.java +++ b/bundles/org.openhab.voice.watsonstt/src/main/java/org/openhab/voice/watsonstt/internal/WatsonSTTConfiguration.java @@ -63,7 +63,13 @@ public class WatsonSTTConfiguration { /** * Message to be told when no results */ - public String noResultsMessage = "No results"; + public String noResultsMessage = "Sorry, I didn't understand you"; + + /** + * Message to be told when an error has happened + */ + public String errorMessage = "Sorry, something went wrong"; + /** * By default, all IBM Watson™ services log requests and their results. Logging is done only to improve the services * for future users. The logged data is not shared or made public. diff --git a/bundles/org.openhab.voice.watsonstt/src/main/java/org/openhab/voice/watsonstt/internal/WatsonSTTService.java b/bundles/org.openhab.voice.watsonstt/src/main/java/org/openhab/voice/watsonstt/internal/WatsonSTTService.java index 70bff2a5742..2220ec1061b 100644 --- a/bundles/org.openhab.voice.watsonstt/src/main/java/org/openhab/voice/watsonstt/internal/WatsonSTTService.java +++ b/bundles/org.openhab.voice.watsonstt/src/main/java/org/openhab/voice/watsonstt/internal/WatsonSTTService.java @@ -311,8 +311,7 @@ public class WatsonSTTService implements STTService { } logger.warn("TranscriptionError: {}", errorMessage); if (!aborted.getAndSet(true)) { - sttListener.sttEventReceived( - new SpeechRecognitionErrorEvent(errorMessage != null ? errorMessage : "Unknown error")); + sttListener.sttEventReceived(new SpeechRecognitionErrorEvent(config.errorMessage)); } } @@ -327,11 +326,7 @@ public class WatsonSTTService implements STTService { if (!transcript.isBlank()) { sttListener.sttEventReceived(new SpeechRecognitionEvent(transcript, averageConfidence)); } else { - if (!config.noResultsMessage.isBlank()) { - sttListener.sttEventReceived(new SpeechRecognitionErrorEvent(config.noResultsMessage)); - } else { - sttListener.sttEventReceived(new SpeechRecognitionErrorEvent("No results")); - } + sttListener.sttEventReceived(new SpeechRecognitionErrorEvent(config.noResultsMessage)); } } } diff --git a/bundles/org.openhab.voice.watsonstt/src/main/resources/OH-INF/config/config.xml b/bundles/org.openhab.voice.watsonstt/src/main/resources/OH-INF/config/config.xml index ed54844ae97..86f85c36eb7 100644 --- a/bundles/org.openhab.voice.watsonstt/src/main/resources/OH-INF/config/config.xml +++ b/bundles/org.openhab.voice.watsonstt/src/main/resources/OH-INF/config/config.xml @@ -47,7 +47,12 @@ Message to be told when no transcription is done. - No results + Sorry, I didn't understand you + + + + Message to be told when an error has happened. + Sorry, something went wrong diff --git a/bundles/org.openhab.voice.watsonstt/src/main/resources/OH-INF/i18n/watsonstt.properties b/bundles/org.openhab.voice.watsonstt/src/main/resources/OH-INF/i18n/watsonstt.properties index 6ca306aac5f..e2920d37cef 100644 --- a/bundles/org.openhab.voice.watsonstt/src/main/resources/OH-INF/i18n/watsonstt.properties +++ b/bundles/org.openhab.voice.watsonstt/src/main/resources/OH-INF/i18n/watsonstt.properties @@ -12,6 +12,8 @@ voice.config.watsonstt.maxSilenceSeconds.label = Max Silence Seconds voice.config.watsonstt.maxSilenceSeconds.description = The time in seconds after which, if only silence (no speech) is detected in the audio, the connection is closed. voice.config.watsonstt.noResultsMessage.label = No Results Message voice.config.watsonstt.noResultsMessage.description = Message to be told when no transcription is done. +voice.config.watsonstt.errorMessage.label = Error Message +voice.config.watsonstt.errorMessage.description = Message to be told when an error has happened. voice.config.watsonstt.optOutLogging.label = Opt Out Logging voice.config.watsonstt.optOutLogging.description = By default, all IBM Watson™ services log requests and their results. Logging is done only to improve the services for future users. The logged data is not shared or made public. voice.config.watsonstt.preferMultimediaModel.label = Prefer Multimedia Model