Skip to content

Commit

Permalink
[vosk] Upgrade sdk and handle UnsatisfiedLinkError exceptions (openha…
Browse files Browse the repository at this point in the history
…b#13391)

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

Signed-off-by: Miguel Álvarez <miguelwork92@gmail.com>
  • Loading branch information
GiviMAD authored and nemerdaud committed Feb 28, 2023
1 parent 6116580 commit b2b8ee1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
2 changes: 1 addition & 1 deletion bundles/org.openhab.voice.voskstt/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<dependency>
<groupId>com.alphacephei</groupId>
<artifactId>vosk</artifactId>
<version>0.3.33</version>
<version>0.3.38</version>
<scope>compile</scope>
</dependency>
<!--Deps -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ private void configChange(Map<String, Object> config) {
loadModel();
} catch (IOException e) {
logger.warn("IOException loading model: {}", e.getMessage());
} catch (UnsatisfiedLinkError e) {
logger.warn("Missing native dependency: {}", e.getMessage());
}
} else {
try {
Expand Down Expand Up @@ -164,15 +166,15 @@ public STTServiceHandle recognize(STTListener sttListener, AudioStream audioStre
};
}

private Model getModel() throws IOException {
private Model getModel() throws IOException, UnsatisfiedLinkError {
var model = this.model;
if (model != null) {
return model;
}
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()) {
Expand Down Expand Up @@ -263,6 +265,13 @@ private Future<?> backgroundRecognize(STTListener sttListener, InputStream audio
} 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();
Expand Down

0 comments on commit b2b8ee1

Please sign in to comment.