[vosk] Upgrade sdk and handle UnsatisfiedLinkError exceptions (#13391)
* [vosk] update sdk * [vosk] handle unsatisfied link error exceptions Signed-off-by: Miguel Álvarez <miguelwork92@gmail.com>pull/13331/head
parent
39d221d3a8
commit
25ffd6127b
bundles/org.openhab.voice.voskstt
src/main/java/org/openhab/voice/voskstt/internal
|
@ -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 -->
|
||||||
|
|
|
@ -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();
|
||||||
|
|
Loading…
Reference in New Issue