porcupine/binding/python/__init__.py
Go to the documentation of this file.
1 #
2 # Copyright 2020-2022 Picovoice Inc.
3 #
4 # You may not use this file except in compliance with the license. A copy of the license is located in the "LICENSE"
5 # file accompanying this source.
6 #
7 # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
8 # an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
9 # specific language governing permissions and limitations under the License.
10 #
11 
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
25 from .util import *
26 
27 LIBRARY_PATH = pv_library_path('')
28 
29 MODEL_PATH = pv_model_path('')
30 
31 KEYWORD_PATHS = pv_keyword_paths('')
32 
33 KEYWORDS = set(KEYWORD_PATHS.keys())
34 
35 
36 def create(access_key, library_path=None, model_path=None, keyword_paths=None, keywords=None, sensitivities=None):
37  """
38  Factory method for Porcupine wake word engine.
39 
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
42  location.
43  :param model_path: Absolute path to the file containing model parameters. If not set it will be set to the default
44  location.
45  :param keyword_paths: Absolute paths to keyword model files. If not set it will be populated from `keywords`
46  argument.
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.
52  """
53 
54  if library_path is None:
55  library_path = LIBRARY_PATH
56 
57  if model_path is None:
58  model_path = MODEL_PATH
59 
60  if keyword_paths is None:
61  if keywords is None:
62  raise ValueError("Either `keywords` or `keyword_paths` must be set.")
63 
64  if all(x in KEYWORDS for x in keywords):
65  keyword_paths = [KEYWORD_PATHS[x] for x in keywords]
66  else:
67  raise ValueError(
68  'One or more keywords are not available by default. Available default keywords are:\\n%s' %
69  ', '.join(KEYWORDS))
70 
71  if sensitivities is None:
72  sensitivities = [0.5] * len(keyword_paths)
73 
74  if len(sensitivities) != len(keyword_paths):
75  raise ValueError("Number of keywords does not match the number of sensitivities.")
76 
77  return Porcupine(
78  access_key=access_key,
79  library_path=library_path,
80  model_path=model_path,
81  keyword_paths=keyword_paths,
82  sensitivities=sensitivities)
python.util.pv_library_path
def pv_library_path(relative)
Definition: porcupine/binding/python/util.py:80
python.create
def create(access_key, library_path=None, model_path=None, keyword_paths=None, keywords=None, sensitivities=None)
Definition: porcupine/binding/python/__init__.py:36
python.util.pv_keyword_paths
def pv_keyword_paths(relative)
Definition: porcupine/binding/python/util.py:129
python.util.pv_model_path
def pv_model_path(relative)
Definition: porcupine/binding/python/util.py:107
python.porcupine.Porcupine
Definition: porcupine.py:65


picovoice_driver
Author(s):
autogenerated on Fri Apr 1 2022 02:13:47