[rustpotterks] Fix for Windows, avoid load library multiple times (#15945)

Signed-off-by: Miguel Álvarez <miguelwork92@gmail.com>
This commit is contained in:
GiviMAD 2023-11-25 05:40:38 -08:00 committed by GitHub
parent 280fdb0962
commit d498b492a0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -61,6 +61,7 @@ import io.github.givimad.rustpotter_java.ScoreMode;
@ConfigurableService(category = SERVICE_CATEGORY, label = SERVICE_NAME
+ " Keyword Spotter", description_uri = SERVICE_CATEGORY + ":" + SERVICE_ID)
public class RustpotterKSService implements KSService {
private boolean libraryLoaded;
private static final String RUSTPOTTER_FOLDER = Path.of(OpenHAB.getUserDataFolder(), "rustpotter").toString();
private final Logger logger = LoggerFactory.getLogger(RustpotterKSService.class);
private final ScheduledExecutorService executor = ThreadPoolManager.getScheduledPool("OH-voice-rustpotterks");
@ -109,11 +110,14 @@ public class RustpotterKSService implements KSService {
@Override
public KSServiceHandle spot(KSListener ksListener, AudioStream audioStream, Locale locale, String keyword)
throws KSException {
logger.debug("Loading library");
try {
Rustpotter.loadLibrary();
} catch (IOException e) {
throw new KSException("Unable to load rustpotter lib: " + e.getMessage());
if (!libraryLoaded) {
logger.debug("Loading library");
try {
Rustpotter.loadLibrary();
libraryLoaded = true;
} catch (IOException e) {
throw new KSException("Unable to load rustpotter lib: " + e.getMessage());
}
}
var audioFormat = audioStream.getFormat();
var frequency = audioFormat.getFrequency();