12 from .porcupine
import Porcupine
13 from .porcupine
import PorcupineError
14 from .porcupine
import PorcupineMemoryError
15 from .porcupine
import PorcupineIOError
16 from .porcupine
import PorcupineInvalidArgumentError
17 from .porcupine
import PorcupineStopIterationError
18 from .porcupine
import PorcupineKeyError
19 from .porcupine
import PorcupineInvalidStateError
20 from .porcupine
import PorcupineRuntimeError
21 from .porcupine
import PorcupineActivationError
22 from .porcupine
import PorcupineActivationLimitError
23 from .porcupine
import PorcupineActivationThrottledError
24 from .porcupine
import PorcupineActivationRefusedError
33 KEYWORDS = set(KEYWORD_PATHS.keys())
36 def create(access_key, library_path=None, model_path=None, keyword_paths=None, keywords=None, sensitivities=None):
38 Factory method for Porcupine wake word engine.
40 :param access_key: AccessKey obtained from Picovoice Console.
41 :param library_path: Absolute path to Porcupine's dynamic library. If not set it will be set to the default
43 :param model_path: Absolute path to the file containing model parameters. If not set it will be set to the default
45 :param keyword_paths: Absolute paths to keyword model files. If not set it will be populated from `keywords`
47 :param keywords: List of keywords (phrases) for detection. The list of available (default) keywords can be
48 retrieved using `pvporcupine.KEYWORDS`. If `keyword_paths` is set then this argument will be ignored.
49 :param sensitivities: Sensitivities for detecting keywords. Each value should be a number within [0, 1]. A higher
50 sensitivity results in fewer misses at the cost of increasing the false alarm rate. If not set 0.5 will be used.
51 :return: An instance of Porcupine wake word engine.
54 if library_path
is None:
55 library_path = LIBRARY_PATH
57 if model_path
is None:
58 model_path = MODEL_PATH
60 if keyword_paths
is None:
62 raise ValueError(
"Either `keywords` or `keyword_paths` must be set.")
64 if all(x
in KEYWORDS
for x
in keywords):
65 keyword_paths = [KEYWORD_PATHS[x]
for x
in keywords]
68 'One or more keywords are not available by default. Available default keywords are:\\n%s' %
71 if sensitivities
is None:
72 sensitivities = [0.5] * len(keyword_paths)
74 if len(sensitivities) != len(keyword_paths):
75 raise ValueError(
"Number of keywords does not match the number of sensitivities.")
78 access_key=access_key,
79 library_path=library_path,
80 model_path=model_path,
81 keyword_paths=keyword_paths,
82 sensitivities=sensitivities)