mirror of
https://github.com/Picovoice/porcupine.git
synced 2022-01-28 03:27:53 +03:00
Release Python package and update demo error logic (#597)
This commit is contained in:
@@ -10,7 +10,18 @@
|
||||
#
|
||||
|
||||
from .porcupine import Porcupine
|
||||
from .porcupine_error import *
|
||||
from .porcupine import PorcupineError
|
||||
from .porcupine import PorcupineMemoryError
|
||||
from .porcupine import PorcupineIOError
|
||||
from .porcupine import PorcupineInvalidArgumentError
|
||||
from .porcupine import PorcupineStopIterationError
|
||||
from .porcupine import PorcupineKeyError
|
||||
from .porcupine import PorcupineInvalidStateError
|
||||
from .porcupine import PorcupineRuntimeError
|
||||
from .porcupine import PorcupineActivationError
|
||||
from .porcupine import PorcupineActivationLimitError
|
||||
from .porcupine import PorcupineActivationThrottledError
|
||||
from .porcupine import PorcupineActivationRefusedError
|
||||
from .util import *
|
||||
|
||||
LIBRARY_PATH = pv_library_path('')
|
||||
|
||||
@@ -13,7 +13,53 @@ import os
|
||||
from ctypes import *
|
||||
from enum import Enum
|
||||
|
||||
from porcupine_error import *
|
||||
|
||||
class PorcupineError(Exception):
|
||||
pass
|
||||
|
||||
|
||||
class PorcupineMemoryError(PorcupineError):
|
||||
pass
|
||||
|
||||
|
||||
class PorcupineIOError(PorcupineError):
|
||||
pass
|
||||
|
||||
|
||||
class PorcupineInvalidArgumentError(PorcupineError):
|
||||
pass
|
||||
|
||||
|
||||
class PorcupineStopIterationError(PorcupineError):
|
||||
pass
|
||||
|
||||
|
||||
class PorcupineKeyError(PorcupineError):
|
||||
pass
|
||||
|
||||
|
||||
class PorcupineInvalidStateError(PorcupineError):
|
||||
pass
|
||||
|
||||
|
||||
class PorcupineRuntimeError(PorcupineError):
|
||||
pass
|
||||
|
||||
|
||||
class PorcupineActivationError(PorcupineError):
|
||||
pass
|
||||
|
||||
|
||||
class PorcupineActivationLimitError(PorcupineError):
|
||||
pass
|
||||
|
||||
|
||||
class PorcupineActivationThrottledError(PorcupineError):
|
||||
pass
|
||||
|
||||
|
||||
class PorcupineActivationRefusedError(PorcupineError):
|
||||
pass
|
||||
|
||||
|
||||
class Porcupine(object):
|
||||
|
||||
@@ -1,57 +0,0 @@
|
||||
#
|
||||
# Copyright 2021 Picovoice Inc.
|
||||
#
|
||||
# You may not use this file except in compliance with the license. A copy of the license is located in the "LICENSE"
|
||||
# file accompanying this source.
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
|
||||
# an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
||||
# specific language governing permissions and limitations under the License.
|
||||
#
|
||||
|
||||
class PorcupineError(Exception):
|
||||
pass
|
||||
|
||||
|
||||
class PorcupineMemoryError(PorcupineError):
|
||||
pass
|
||||
|
||||
|
||||
class PorcupineIOError(PorcupineError):
|
||||
pass
|
||||
|
||||
|
||||
class PorcupineInvalidArgumentError(PorcupineError):
|
||||
pass
|
||||
|
||||
|
||||
class PorcupineStopIterationError(PorcupineError):
|
||||
pass
|
||||
|
||||
|
||||
class PorcupineKeyError(PorcupineError):
|
||||
pass
|
||||
|
||||
|
||||
class PorcupineInvalidStateError(PorcupineError):
|
||||
pass
|
||||
|
||||
|
||||
class PorcupineRuntimeError(PorcupineError):
|
||||
pass
|
||||
|
||||
|
||||
class PorcupineActivationError(PorcupineError):
|
||||
pass
|
||||
|
||||
|
||||
class PorcupineActivationLimitError(PorcupineError):
|
||||
pass
|
||||
|
||||
|
||||
class PorcupineActivationThrottledError(PorcupineError):
|
||||
pass
|
||||
|
||||
|
||||
class PorcupineActivationRefusedError(PorcupineError):
|
||||
pass
|
||||
@@ -42,7 +42,6 @@ MANIFEST_IN = """
|
||||
include pvporcupine/LICENSE
|
||||
include pvporcupine/__init__.py
|
||||
include pvporcupine/porcupine.py
|
||||
include pvporcupine/porcupine_error.py
|
||||
include pvporcupine/util.py
|
||||
include pvporcupine/lib/common/porcupine_params.pv
|
||||
include pvporcupine/lib/beaglebone/libpv_porcupine.so
|
||||
@@ -68,7 +67,7 @@ with open(os.path.join(os.path.dirname(__file__), 'README.md'), 'r') as f:
|
||||
|
||||
setuptools.setup(
|
||||
name="pvporcupine",
|
||||
version="2.0.1",
|
||||
version="2.0.4",
|
||||
author="Picovoice",
|
||||
author_email="hello@picovoice.ai",
|
||||
description="Porcupine wake word engine.",
|
||||
|
||||
@@ -89,12 +89,32 @@ def main():
|
||||
if len(keyword_paths) != len(args.sensitivities):
|
||||
raise ValueError('Number of keywords does not match the number of sensitivities.')
|
||||
|
||||
porcupine = pvporcupine.create(
|
||||
access_key=args.access_key,
|
||||
library_path=args.library_path,
|
||||
model_path=args.model_path,
|
||||
keyword_paths=keyword_paths,
|
||||
sensitivities=args.sensitivities)
|
||||
try:
|
||||
porcupine = pvporcupine.create(
|
||||
access_key=args.access_key,
|
||||
library_path=args.library_path,
|
||||
model_path=args.model_path,
|
||||
keyword_paths=keyword_paths,
|
||||
sensitivities=args.sensitivities)
|
||||
except pvporcupine.PorcupineInvalidArgumentError as e:
|
||||
print(f"One or more arguments provided to Porcupine is invalid: {args}")
|
||||
print(f"If all other arguments seem valid, ensure that '{args.access_key}' is a valid AccessKey")
|
||||
raise e
|
||||
except pvporcupine.PorcupineActivationError as e:
|
||||
print("AccessKey activation error")
|
||||
raise e
|
||||
except pvporcupine.PorcupineActivationLimitError as e:
|
||||
print(f"AccessKey '{args.access_key}' has reached it's temporary device limit")
|
||||
raise e
|
||||
except pvporcupine.PorcupineActivationRefusedError as e:
|
||||
print(f"AccessKey '{args.access_key}' refused")
|
||||
raise e
|
||||
except pvporcupine.PorcupineActivationThrottledError as e:
|
||||
print(f"AccessKey '{args.access_key}' has been throttled")
|
||||
raise e
|
||||
except pvporcupine.PorcupineError as e:
|
||||
print(f"Failed to initialize Porcupine")
|
||||
raise e
|
||||
|
||||
audio = read_file(args.input_audio_path, porcupine.sample_rate)
|
||||
|
||||
|
||||
@@ -110,7 +110,31 @@ class PorcupineDemo(Thread):
|
||||
result = porcupine.process(pcm)
|
||||
if result >= 0:
|
||||
print('[%s] Detected %s' % (str(datetime.now()), keywords[result]))
|
||||
|
||||
except pvporcupine.PorcupineInvalidArgumentError as e:
|
||||
print("One or more arguments provided to Porcupine is invalid: {\n" +
|
||||
f"\t{self._access_key=}\n" +
|
||||
f"\t{self._library_path=}\n" +
|
||||
f"\t{self._model_path=}\n" +
|
||||
f"\t{self._keyword_paths=}\n" +
|
||||
f"\t{self._sensitivities=}\n" +
|
||||
"}")
|
||||
print(f"If all other arguments seem valid, ensure that '{self._access_key}' is a valid AccessKey")
|
||||
raise e
|
||||
except pvporcupine.PorcupineActivationError as e:
|
||||
print("AccessKey activation error")
|
||||
raise e
|
||||
except pvporcupine.PorcupineActivationLimitError as e:
|
||||
print(f"AccessKey '{self._access_key}' has reached it's temporary device limit")
|
||||
raise e
|
||||
except pvporcupine.PorcupineActivationRefusedError as e:
|
||||
print(f"AccessKey '{self._access_key}' refused")
|
||||
raise e
|
||||
except pvporcupine.PorcupineActivationThrottledError as e:
|
||||
print(f"AccessKey '{self._access_key}' has been throttled")
|
||||
raise e
|
||||
except pvporcupine.PorcupineError as e:
|
||||
print(f"Failed to initialize Porcupine")
|
||||
raise e
|
||||
except KeyboardInterrupt:
|
||||
print('Stopping ...')
|
||||
finally:
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
pvporcupine==2.0.1
|
||||
pvporcupine==2.0.4
|
||||
pvrecorder==1.0.2
|
||||
|
||||
@@ -28,7 +28,7 @@ with open(os.path.join(os.path.dirname(__file__), 'README.md'), 'r') as f:
|
||||
|
||||
setuptools.setup(
|
||||
name="pvporcupinedemo",
|
||||
version="2.0.3",
|
||||
version="2.0.4",
|
||||
author="Picovoice",
|
||||
author_email="hello@picovoice.ai",
|
||||
description="Porcupine wake word engine demos",
|
||||
@@ -36,7 +36,7 @@ setuptools.setup(
|
||||
long_description_content_type="text/markdown",
|
||||
url="https://github.com/Picovoice/porcupine",
|
||||
packages=["pvporcupinedemo"],
|
||||
install_requires=["pvporcupine==2.0.1", "pvrecorder==1.0.2"],
|
||||
install_requires=["pvporcupine==2.0.4", "pvrecorder==1.0.2"],
|
||||
include_package_data=True,
|
||||
classifiers=[
|
||||
"Development Status :: 5 - Production/Stable",
|
||||
|
||||
Reference in New Issue
Block a user