]> git.basschouten.com Git - openhab-addons.git/commitdiff
[porcupineks] fix build-in keywords on windows, fix service name and add missed modif...
authorGiviMAD <GiviMAD@users.noreply.github.com>
Thu, 3 Mar 2022 21:47:02 +0000 (22:47 +0100)
committerGitHub <noreply@github.com>
Thu, 3 Mar 2022 21:47:02 +0000 (22:47 +0100)
* [porcupineks] fix windows and add modified
* [porcupineks] fix service name

Signed-off-by: Miguel Álvarez Díez <miguelwork92@gmail.com>
bundles/org.openhab.voice.porcupineks/src/main/java/org/openhab/voice/porcupineks/internal/PorcupineKSConstants.java
bundles/org.openhab.voice.porcupineks/src/main/java/org/openhab/voice/porcupineks/internal/PorcupineKSService.java

index 154d73fbd4833be52cb0fa1cd5aca6087430e93d..5d0acbefcfcdcb32cd83a692f3f3c11f0cb8b005 100644 (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
index c5174bae88aa469b05ac24e00fa84024ef2f2cf4..20c7b6f488ef0f7aad2c467f706beb3f7cd04b48 100644 (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(