[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
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

View File

@ -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 -->

View File

@ -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();