Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from
Nov 25, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
@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");
Expand Down Expand Up @@ -109,11 +110,14 @@ public Set<AudioFormat> getSupportedFormats() {
@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();
Expand Down