]> git.basschouten.com Git - openhab-addons.git/commitdiff
[voice] Allow speech-to-text services to emit empty error events (#16922)
authorGiviMAD <GiviMAD@users.noreply.github.com>
Sun, 23 Jun 2024 21:21:55 +0000 (23:21 +0200)
committerGitHub <noreply@github.com>
Sun, 23 Jun 2024 21:21:55 +0000 (23:21 +0200)
* [voice] Align speech-to-text services error events to core

Signed-off-by: Miguel Álvarez <miguelwork92@gmail.com>
bundles/org.openhab.voice.googlestt/src/main/java/org/openhab/voice/googlestt/internal/GoogleSTTService.java
bundles/org.openhab.voice.voskstt/src/main/java/org/openhab/voice/voskstt/internal/VoskSTTService.java
bundles/org.openhab.voice.watsonstt/README.md
bundles/org.openhab.voice.watsonstt/src/main/java/org/openhab/voice/watsonstt/internal/WatsonSTTConfiguration.java
bundles/org.openhab.voice.watsonstt/src/main/java/org/openhab/voice/watsonstt/internal/WatsonSTTService.java
bundles/org.openhab.voice.watsonstt/src/main/resources/OH-INF/config/config.xml
bundles/org.openhab.voice.watsonstt/src/main/resources/OH-INF/i18n/watsonstt.properties

index a217c6a4170683e32a5804fbdb15d39db13e9b7e..d3eca88a0d10200aba678479a48c068fd68e6d51 100644 (file)
@@ -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));
             }
         }
 
index b4d38392140bb691b920fc69d01de31d482632e6..121655b9e42a34f0af063bc631fb81acbdad6d35 100644 (file)
@@ -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();
index 46ba04c50e06a9917ca6ddc05b07f83cdbfcdae9..c9610b56cc145e3f80933a9b540523f5c353cb95 100644 (file)
@@ -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
index ca5a089126d9d8456ab3c06f9a5e2bac4229afa3..818cc6f228a9ccd7a1b83fe28fc4bd042b8646ef 100644 (file)
@@ -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.
index 70bff2a574206469e82e154978757aaedcb1ebd8..2220ec1061bb5985a8a62030fd03e236fe585e3d 100644 (file)
@@ -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));
                 }
             }
         }
index ed54844ae97fc54c629424a949e1bac711e4976c..86f85c36eb76b7307dbcb141b2446df37d9c361c 100644 (file)
                <parameter name="noResultsMessage" type="text" groupName="stt">
                        <label>No Results Message</label>
                        <description>Message to be told when no transcription is done.</description>
-                       <default>No results</default>
+                       <default>Sorry, I didn't understand you</default>
+               </parameter>
+               <parameter name="errorMessage" type="text" groupName="stt">
+                       <label>Error Message</label>
+                       <description>Message to be told when an error has happened.</description>
+                       <default>Sorry, something went wrong</default>
                </parameter>
                <parameter name="singleUtteranceMode" type="boolean" groupName="stt">
                        <label>Single Utterance Mode</label>
index 6ca306aac5fe4e9fdbec18ef27e761d3a1943792..e2920d37cef02e164147fa6875cff6e0b02259ee 100644 (file)
@@ -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