[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:
GiviMAD 2022-03-03 22:47:02 +01:00 committed by GitHub
parent 2cce90f83d
commit fb9f0d8d43
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 6 deletions

View File

@ -25,7 +25,7 @@ public class PorcupineKSConstants {
/**
* Service name
*/
public static final String SERVICE_NAME = "Porcupine Keyword Spotter";
public static final String SERVICE_NAME = "Porcupine";
/**
* Service id

View File

@ -55,6 +55,7 @@ import org.osgi.framework.Constants;
import org.osgi.service.component.ComponentContext;
import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Modified;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -68,8 +69,8 @@ import ai.picovoice.porcupine.PorcupineException;
*/
@NonNullByDefault
@Component(configurationPid = SERVICE_PID, property = Constants.SERVICE_PID + "=" + SERVICE_PID)
@ConfigurableService(category = SERVICE_CATEGORY, label = SERVICE_NAME, description_uri = SERVICE_CATEGORY + ":"
+ SERVICE_ID)
@ConfigurableService(category = SERVICE_CATEGORY, label = SERVICE_NAME
+ " Keyword Spotter", description_uri = SERVICE_CATEGORY + ":" + SERVICE_ID)
public class PorcupineKSService implements KSService {
private static final String PORCUPINE_FOLDER = Path.of(OpenHAB.getUserDataFolder(), "porcupine").toString();
private static final String EXTRACTION_FOLDER = Path.of(OpenHAB.getUserDataFolder(), "porcupine", "extracted")
@ -98,8 +99,13 @@ public class PorcupineKSService implements KSService {
@Activate
protected void activate(ComponentContext componentContext, Map<String, Object> config) {
this.config = new Configuration(config).as(PorcupineKSConfiguration.class);
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()) {
logger.warn("Missing pico voice api key to use Porcupine Keyword Spotter");
}
@ -288,8 +294,9 @@ public class PorcupineKSService implements KSService {
+ localKeywordPath);
}
String env = getPorcupineEnv();
String keywordPath = "porcupine/resources/keyword_files/" + env + "/" + keyWord.replace(" ", "_") + "_"
+ env + ".ppn";
String keywordPath = Path
.of("porcupine", "resources", "keyword_files", env, keyWord.replace(" ", "_") + "_" + env + ".ppn")
.toString();
return prepareLib(bundleContext, keywordPath);
} else {
throw new IllegalArgumentException(