[vosk] Upgrade sdk and handle UnsatisfiedLinkError exceptions ()

* [vosk] update sdk
* [vosk] handle unsatisfied link error exceptions

Signed-off-by: Miguel Álvarez <miguelwork92@gmail.com>
pull/13331/head
GiviMAD 2022-09-17 09:27:09 +02:00 committed by GitHub
parent 39d221d3a8
commit 25ffd6127b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 3 deletions
bundles/org.openhab.voice.voskstt
src/main/java/org/openhab/voice/voskstt/internal

View File

@ -17,7 +17,7 @@
<dependency> <dependency>
<groupId>com.alphacephei</groupId> <groupId>com.alphacephei</groupId>
<artifactId>vosk</artifactId> <artifactId>vosk</artifactId>
<version>0.3.33</version> <version>0.3.38</version>
<scope>compile</scope> <scope>compile</scope>
</dependency> </dependency>
<!--Deps --> <!--Deps -->

View File

@ -113,6 +113,8 @@ public class VoskSTTService implements STTService {
loadModel(); loadModel();
} catch (IOException e) { } catch (IOException e) {
logger.warn("IOException loading model: {}", e.getMessage()); logger.warn("IOException loading model: {}", e.getMessage());
} catch (UnsatisfiedLinkError e) {
logger.warn("Missing native dependency: {}", e.getMessage());
} }
} else { } else {
try { 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; var model = this.model;
if (model != null) { if (model != null) {
return model; return model;
@ -172,7 +174,7 @@ public class VoskSTTService implements STTService {
return loadModel(); return loadModel();
} }
private Model loadModel() throws IOException { private Model loadModel() throws IOException, UnsatisfiedLinkError {
unloadModel(); unloadModel();
var modelFile = new File(MODEL_PATH); var modelFile = new File(MODEL_PATH);
if (!modelFile.exists() || !modelFile.isDirectory()) { if (!modelFile.exists() || !modelFile.isDirectory()) {
@ -263,6 +265,13 @@ public class VoskSTTService implements STTService {
} else { } 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));
}
} finally { } finally {
if (recognizer != null) { if (recognizer != null) {
recognizer.close(); recognizer.close();