|
@@ -1,4 +1,6 @@
|
|
|
+import inspect
|
|
|
import logging
|
|
|
+import os
|
|
|
import time
|
|
|
|
|
|
from kalliope.trigger.snowboy import snowboydecoder
|
|
@@ -29,7 +31,10 @@ class Snowboy(object):
|
|
|
if self.pmdl is None:
|
|
|
raise MissingParameterException("Pmdl file is required with snowboy")
|
|
|
|
|
|
- self.detector = snowboydecoder.HotwordDetector(self.pmdl, sensitivity=0.5, detected_callback=self.callback,
|
|
|
+ # get the pmdl path from root of kalliope module
|
|
|
+ self.pmdl_path = self._get_root_pmdl_path(self.pmdl)
|
|
|
+
|
|
|
+ self.detector = snowboydecoder.HotwordDetector(self.pmdl_path, sensitivity=0.5, detected_callback=self.callback,
|
|
|
interrupt_check=self.interrupt_callback,
|
|
|
sleep_time=0.03)
|
|
|
|
|
@@ -72,3 +77,23 @@ class Snowboy(object):
|
|
|
"""
|
|
|
logger.debug("Unpausing snowboy process")
|
|
|
self.detector.paused = False
|
|
|
+
|
|
|
+ @staticmethod
|
|
|
+ def _get_root_pmdl_path(pmdl_file):
|
|
|
+ """
|
|
|
+ Return the full path of the pmdl file
|
|
|
+ :Example:
|
|
|
+ pmdl_path = cls._get_root_pmdl_path(pmdl_file)
|
|
|
+ .. raises:: IOError
|
|
|
+ .. warnings:: Static method and Private
|
|
|
+ """
|
|
|
+
|
|
|
+ # get current script directory path. We are in /an/unknown/path/kalliope/trigger/snowboy
|
|
|
+ cur_script_directory = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))
|
|
|
+ # get parent dir. Now we are in /an/unknown/path/kalliope
|
|
|
+ parent_dir = os.path.normpath(cur_script_directory + os.sep + os.pardir + os.sep + os.pardir)
|
|
|
+ pmdl_path = parent_dir + os.sep + pmdl_file
|
|
|
+ logger.debug("Real pmdl_file path: %s" % pmdl_path)
|
|
|
+ if os.path.isfile(pmdl_path):
|
|
|
+ return pmdl_path
|
|
|
+ raise IOError("Pmdl file not found: %s" % pmdl_path)
|