class PorcupineEngine(Engine): def __init__(self, keyword, sensitivity): self._porcupine = Porcupine( library_path=os.path.join(self._repo_path, 'lib/linux/x86_64/libpv_porcupine.so'), model_file_path=os.path.join(self._repo_path, 'lib/common/porcupine_params.pv'), keyword_file_path=os.path.join( self._repo_path, 'resources/keyword_files/linux/%s_linux.ppn' % keyword.lower()), sensitivity=sensitivity) def process(self, pcm): assert pcm.dtype == np.int16 return self._porcupine.process(pcm) def release(self): self._porcupine.delete() def __str__(self): return 'Porcupine' @property def _repo_path(self): return os.path.join(os.path.dirname(__file__), 'engines/porcupine')
class PorcupineEngine(Engine): """Porcupine engine.""" def __init__(self, engine_type, keyword, sensitivity): """Initializer. :param engine_type: type of the engine. :param keyword: keyword being used for detection. :param sensitivity: sensitivity passed to the engine. """ super().__init__(engine_type, keyword, sensitivity) library_path = os.path.join( os.path.dirname(__file__), 'engines/porcupine/lib/linux/%s/libpv_porcupine.so' % platform.machine()) model_file_path = os.path.join( os.path.dirname(__file__), 'engines/porcupine/lib/common/porcupine_params.pv') keyword_file_path = os.path.join( os.path.dirname(__file__), 'engines/porcupine/resources/keyword_files/%s_linux.ppn' % keyword.lower()) self._porcupine = Porcupine(library_path=library_path, model_file_path=model_file_path, keyword_file_path=keyword_file_path, sensitivity=sensitivity) @prepare_pcm def process(self, pcm): """Process the PCM data for the keyword.""" return self._porcupine.process(pcm) def release(self): """Release the resources hold by the engine.""" self._porcupine.delete()
class PorcupineEngineBase(Engine): """Base class for different variants of Porcupine engine.""" def __init__(self, sensitivity, model_file_path, keyword_file_path): """ Constructor. :param sensitivity: detection sensitivity. :param model_file_path: path to model file. :param keyword_file_path: path to keyword file. """ library_path = os.path.join( os.path.dirname(__file__), 'engines/porcupine/lib/linux/%s/libpv_porcupine.so' % platform.machine()) self._porcupine = Porcupine(library_path=library_path, model_file_path=model_file_path, keyword_file_path=keyword_file_path, sensitivity=sensitivity) def process(self, pcm): pcm = (np.iinfo(np.int16).max * pcm).astype(np.int16) return self._porcupine.process(pcm) def release(self): self._porcupine.delete() def __str__(self): raise NotImplementedError()
def __init__(self, keyword, sensitivity): self._porcupine = Porcupine( library_path=os.path.join(self._repo_path, 'lib/linux/x86_64/libpv_porcupine.so'), model_file_path=os.path.join(self._repo_path, 'lib/common/porcupine_params.pv'), keyword_file_path=os.path.join( self._repo_path, 'resources/keyword_files/linux/%s_linux.ppn' % keyword.lower()), sensitivity=sensitivity)
def __init__(self, keyword, sensitivity, access_key): self._porcupine = Porcupine( access_key=access_key, library_path=os.path.join(self._repo_path, 'lib/linux/x86_64/libpv_porcupine.so'), model_path=os.path.join(self._repo_path, 'lib/common/porcupine_params.pv'), keyword_paths=[ os.path.join( self._repo_path, 'resources/keyword_files/linux/%s_linux.ppn' % keyword.lower()) ], sensitivities=[sensitivity])
def __init__(self, sensitivity, model_file_path, keyword_file_path): """ Constructor. :param sensitivity: detection sensitivity. :param model_file_path: path to model file. :param keyword_file_path: path to keyword file. """ library_path = os.path.join( os.path.dirname(__file__), 'engines/porcupine/lib/linux/%s/libpv_porcupine.so' % platform.machine()) self._porcupine = Porcupine(library_path=library_path, model_file_path=model_file_path, keyword_file_path=keyword_file_path, sensitivity=sensitivity)
class PorcupineEngineBase(Engine): def __init__(self, model_file_path, keyword_file_path, sensitivity): self._porcupine = Porcupine(library_path=os.path.join( self._repo_path, 'lib/linux/x86_64/libpv_porcupine.so'), model_file_path=model_file_path, keyword_file_path=keyword_file_path, sensitivity=sensitivity) def process(self, pcm): assert pcm.dtype == np.int16 return self._porcupine.process(pcm) def release(self): self._porcupine.delete() def __str__(self): raise NotImplementedError() @property def _repo_path(self): return os.path.join(os.path.dirname(__file__), 'engines/porcupine')
def __init__(self, engine_type, keyword, sensitivity): """Initializer. :param engine_type: type of the engine. :param keyword: keyword being used for detection. :param sensitivity: sensitivity passed to the engine. """ super().__init__(engine_type, keyword, sensitivity) library_path = os.path.join( os.path.dirname(__file__), 'engines/porcupine/lib/linux/%s/libpv_porcupine.so' % platform.machine()) model_file_path = os.path.join( os.path.dirname(__file__), 'engines/porcupine/lib/common/porcupine_params.pv') keyword_file_path = os.path.join( os.path.dirname(__file__), 'engines/porcupine/resources/keyword_files/%s_linux.ppn' % keyword.lower()) self._porcupine = Porcupine(library_path=library_path, model_file_path=model_file_path, keyword_file_path=keyword_file_path, sensitivity=sensitivity)
def __init__(self, model_file_path, keyword_file_path, sensitivity): self._porcupine = Porcupine(library_path=os.path.join( self._repo_path, 'lib/linux/x86_64/libpv_porcupine.so'), model_file_path=model_file_path, keyword_file_path=keyword_file_path, sensitivity=sensitivity)