[voskstt] Fix load on linux arm (#13556)
Signed-off-by: Miguel Álvarez <miguelwork92@gmail.com>
This commit is contained in:
parent
df74075d31
commit
4bba6efe24
|
@ -17,6 +17,8 @@ The following platforms are supported:
|
|||
* osx
|
||||
* win64
|
||||
|
||||
**On Linux this binary requires the package libatomic to be installed (apt install libatomic1).**
|
||||
|
||||
## Configuring the model
|
||||
|
||||
Before you can use this service you should configure your language model.
|
||||
|
|
|
@ -56,6 +56,7 @@ import org.vosk.Model;
|
|||
import org.vosk.Recognizer;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.sun.jna.NativeLibrary;
|
||||
|
||||
/**
|
||||
* The {@link VoskSTTService} class is a service implementation to use Vosk-API for Speech-to-Text.
|
||||
|
@ -77,11 +78,6 @@ public class VoskSTTService implements STTService {
|
|||
logger.info("vosk dir created {}", VOSK_FOLDER);
|
||||
}
|
||||
}
|
||||
try {
|
||||
LibVosk.setLogLevel(LogLevel.WARNINGS);
|
||||
} catch (UnsatisfiedLinkError e) {
|
||||
logger.warn("UnsatisfiedLinkError: {}", e.getMessage());
|
||||
}
|
||||
}
|
||||
private final Logger logger = LoggerFactory.getLogger(VoskSTTService.class);
|
||||
private final ScheduledExecutorService executor = ThreadPoolManager.getScheduledPool("OH-voice-voskstt");
|
||||
|
@ -96,7 +92,18 @@ public class VoskSTTService implements STTService {
|
|||
|
||||
@Activate
|
||||
protected void activate(Map<String, Object> config) {
|
||||
configChange(config);
|
||||
try {
|
||||
String osName = System.getProperty("os.name", "generic").toLowerCase();
|
||||
String osArch = System.getProperty("os.arch", "").toLowerCase();
|
||||
if (osName.contains("linux") && (osArch.equals("arm") || osArch.equals("armv7l"))) {
|
||||
// workaround for loading required shared libraries
|
||||
loadSharedLibrariesArmv7l();
|
||||
}
|
||||
LibVosk.setLogLevel(LogLevel.WARNINGS);
|
||||
configChange(config);
|
||||
} catch (LinkageError e) {
|
||||
logger.warn("LinkageError, service will not work: {}", e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Modified
|
||||
|
@ -305,4 +312,22 @@ public class VoskSTTService implements STTService {
|
|||
private boolean isExpiredInterval(long interval, long referenceTime) {
|
||||
return System.currentTimeMillis() - referenceTime > interval;
|
||||
}
|
||||
|
||||
private void loadSharedLibrariesArmv7l() {
|
||||
logger.debug("loading required shared libraries for linux arm");
|
||||
var libatomicArmLibPath = Path.of("/usr/lib/arm-linux-gnueabihf/libatomic.so.1");
|
||||
if (libatomicArmLibPath.toFile().exists()) {
|
||||
var libatomicArmLibFolderPath = libatomicArmLibPath.getParent().toAbsolutePath();
|
||||
String libraryPath = System.getProperty("jna.library.path", System.getProperty("java.library.path"));
|
||||
if (!libraryPath.contains(libatomicArmLibFolderPath.toString())) {
|
||||
libraryPath = libatomicArmLibFolderPath + "/:" + libraryPath;
|
||||
System.setProperty("jna.library.path", libraryPath);
|
||||
logger.debug("jna library path updated: {}", libraryPath);
|
||||
}
|
||||
NativeLibrary.getInstance("libatomic");
|
||||
logger.debug("loaded libatomic shared library");
|
||||
} else {
|
||||
throw new LinkageError("Required shared library libatomic is missing");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue