[porcupineks] fix build-in keywords on windows, fix service name and add missed modified (#12410)
* [porcupineks] fix windows and add modified * [porcupineks] fix service name Signed-off-by: Miguel Álvarez Díez <miguelwork92@gmail.com>
This commit is contained in:
parent
2cce90f83d
commit
fb9f0d8d43
|
@ -25,7 +25,7 @@ public class PorcupineKSConstants {
|
||||||
/**
|
/**
|
||||||
* Service name
|
* Service name
|
||||||
*/
|
*/
|
||||||
public static final String SERVICE_NAME = "Porcupine Keyword Spotter";
|
public static final String SERVICE_NAME = "Porcupine";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Service id
|
* Service id
|
||||||
|
|
|
@ -55,6 +55,7 @@ import org.osgi.framework.Constants;
|
||||||
import org.osgi.service.component.ComponentContext;
|
import org.osgi.service.component.ComponentContext;
|
||||||
import org.osgi.service.component.annotations.Activate;
|
import org.osgi.service.component.annotations.Activate;
|
||||||
import org.osgi.service.component.annotations.Component;
|
import org.osgi.service.component.annotations.Component;
|
||||||
|
import org.osgi.service.component.annotations.Modified;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
@ -68,8 +69,8 @@ import ai.picovoice.porcupine.PorcupineException;
|
||||||
*/
|
*/
|
||||||
@NonNullByDefault
|
@NonNullByDefault
|
||||||
@Component(configurationPid = SERVICE_PID, property = Constants.SERVICE_PID + "=" + SERVICE_PID)
|
@Component(configurationPid = SERVICE_PID, property = Constants.SERVICE_PID + "=" + SERVICE_PID)
|
||||||
@ConfigurableService(category = SERVICE_CATEGORY, label = SERVICE_NAME, description_uri = SERVICE_CATEGORY + ":"
|
@ConfigurableService(category = SERVICE_CATEGORY, label = SERVICE_NAME
|
||||||
+ SERVICE_ID)
|
+ " Keyword Spotter", description_uri = SERVICE_CATEGORY + ":" + SERVICE_ID)
|
||||||
public class PorcupineKSService implements KSService {
|
public class PorcupineKSService implements KSService {
|
||||||
private static final String PORCUPINE_FOLDER = Path.of(OpenHAB.getUserDataFolder(), "porcupine").toString();
|
private static final String PORCUPINE_FOLDER = Path.of(OpenHAB.getUserDataFolder(), "porcupine").toString();
|
||||||
private static final String EXTRACTION_FOLDER = Path.of(OpenHAB.getUserDataFolder(), "porcupine", "extracted")
|
private static final String EXTRACTION_FOLDER = Path.of(OpenHAB.getUserDataFolder(), "porcupine", "extracted")
|
||||||
|
@ -98,8 +99,13 @@ public class PorcupineKSService implements KSService {
|
||||||
|
|
||||||
@Activate
|
@Activate
|
||||||
protected void activate(ComponentContext componentContext, Map<String, Object> config) {
|
protected void activate(ComponentContext componentContext, Map<String, Object> config) {
|
||||||
this.config = new Configuration(config).as(PorcupineKSConfiguration.class);
|
|
||||||
this.bundleContext = componentContext.getBundleContext();
|
this.bundleContext = componentContext.getBundleContext();
|
||||||
|
modified(config);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Modified
|
||||||
|
protected void modified(Map<String, Object> config) {
|
||||||
|
this.config = new Configuration(config).as(PorcupineKSConfiguration.class);
|
||||||
if (this.config.apiKey.isBlank()) {
|
if (this.config.apiKey.isBlank()) {
|
||||||
logger.warn("Missing pico voice api key to use Porcupine Keyword Spotter");
|
logger.warn("Missing pico voice api key to use Porcupine Keyword Spotter");
|
||||||
}
|
}
|
||||||
|
@ -288,8 +294,9 @@ public class PorcupineKSService implements KSService {
|
||||||
+ localKeywordPath);
|
+ localKeywordPath);
|
||||||
}
|
}
|
||||||
String env = getPorcupineEnv();
|
String env = getPorcupineEnv();
|
||||||
String keywordPath = "porcupine/resources/keyword_files/" + env + "/" + keyWord.replace(" ", "_") + "_"
|
String keywordPath = Path
|
||||||
+ env + ".ppn";
|
.of("porcupine", "resources", "keyword_files", env, keyWord.replace(" ", "_") + "_" + env + ".ppn")
|
||||||
|
.toString();
|
||||||
return prepareLib(bundleContext, keywordPath);
|
return prepareLib(bundleContext, keywordPath);
|
||||||
} else {
|
} else {
|
||||||
throw new IllegalArgumentException(
|
throw new IllegalArgumentException(
|
||||||
|
|
Loading…
Reference in New Issue