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