From: GiviMAD Date: Sat, 17 Sep 2022 07:27:09 +0000 (+0200) Subject: [vosk] Upgrade sdk and handle UnsatisfiedLinkError exceptions (#13391) X-Git-Url: https://git.basschouten.com/?a=commitdiff_plain;h=25ffd6127b0c310703fcc2169f6e06f32746883b;p=openhab-addons.git [vosk] Upgrade sdk and handle UnsatisfiedLinkError exceptions (#13391) * [vosk] update sdk * [vosk] handle unsatisfied link error exceptions Signed-off-by: Miguel Álvarez --- diff --git a/bundles/org.openhab.voice.voskstt/pom.xml b/bundles/org.openhab.voice.voskstt/pom.xml index 8a32bcc9c1..ca0554b900 100644 --- a/bundles/org.openhab.voice.voskstt/pom.xml +++ b/bundles/org.openhab.voice.voskstt/pom.xml @@ -17,7 +17,7 @@ com.alphacephei vosk - 0.3.33 + 0.3.38 compile 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 532ffbb22c..c1e0bce66e 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 @@ -113,6 +113,8 @@ public class VoskSTTService implements STTService { loadModel(); } catch (IOException e) { logger.warn("IOException loading model: {}", e.getMessage()); + } catch (UnsatisfiedLinkError e) { + logger.warn("Missing native dependency: {}", e.getMessage()); } } else { try { @@ -164,7 +166,7 @@ public class VoskSTTService implements STTService { }; } - private Model getModel() throws IOException { + private Model getModel() throws IOException, UnsatisfiedLinkError { var model = this.model; if (model != null) { return model; @@ -172,7 +174,7 @@ public class VoskSTTService implements STTService { return loadModel(); } - private Model loadModel() throws IOException { + private Model loadModel() throws IOException, UnsatisfiedLinkError { unloadModel(); var modelFile = new File(MODEL_PATH); if (!modelFile.exists() || !modelFile.isDirectory()) { @@ -263,6 +265,13 @@ public class VoskSTTService implements STTService { } else { 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)); + } } finally { if (recognizer != null) { recognizer.close();