Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Porcupine v2 #11

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,10 @@ $ bin/rhasspy-wake-porcupine-hermes <ARGS>

```
usage: rhasspy-wake-porcupine-hermes [-h] --keyword KEYWORD
[--access-key ACCESS_KEY]
[--keyword-dir KEYWORD_DIR]
[--library LIBRARY] [--model MODEL]
[--library LIBRARY]
[--model MODEL]
[--wakeword-id WAKEWORD_ID]
[--sensitivity SENSITIVITY]
[--stdin-audio]
Expand All @@ -50,12 +52,15 @@ usage: rhasspy-wake-porcupine-hermes [-h] --keyword KEYWORD

optional arguments:
-h, --help show this help message and exit
--access-key ACCESS_KEY
Porcupine access key
--keyword KEYWORD Path(s) to one or more Porcupine keyword file(s)
(.ppn)
--keyword-dir KEYWORD_DIR
Path to directory with keyword files
--library LIBRARY Path to Porcupine shared library (.so)
--model MODEL Path to Porcupine model (.pv)
--model MODEL Absolute path to the file containing model parameters (.pv)
Default: using the library provided by `pvporcupine`
--wakeword-id WAKEWORD_ID
Wakeword IDs of each keyword (default: use file name)
--sensitivity SENSITIVITY
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
paho-mqtt==1.5.0
pvporcupine~=1.9.0
pvporcupine~=2.2.1
rhasspy-hermes~=0.6.0
8 changes: 7 additions & 1 deletion rhasspywake_porcupine_hermes/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class SiteInfo:
detection_thread: typing.Optional[threading.Thread] = None
audio_buffer: bytes = bytes()
first_audio: bool = True
porcupine: typing.Optional[pvporcupine.porcupine.Porcupine] = None
porcupine: typing.Optional[pvporcupine.Porcupine] = None

# Queue of (bytes, is_raw)
wav_queue: "queue.Queue[typing.Tuple[bytes, bool]]" = field(
Expand Down Expand Up @@ -72,11 +72,13 @@ class WakeHermesMqtt(HermesClient):
def __init__(
self,
client,
access_key: str,
model_ids: typing.List[str],
wakeword_ids: typing.List[str],
sensitivities: typing.List[float],
keyword_dirs: typing.Optional[typing.List[Path]] = None,
site_ids: typing.Optional[typing.List[str]] = None,
model_path: typing.Optional[str] = None,
sample_rate: int = 16000,
sample_width: int = 2,
channels: int = 1,
Expand All @@ -97,8 +99,10 @@ def __init__(

self.subscribe(AudioFrame, HotwordToggleOn, HotwordToggleOff, GetHotwords)

self.access_key = access_key
self.wakeword_ids = wakeword_ids
self.model_ids = model_ids
self.model_path = model_path
self.sensitivities = sensitivities

self.keyword_dirs = keyword_dirs or []
Expand Down Expand Up @@ -250,7 +254,9 @@ def detection_thread_proc(self, site_info: SiteInfo):
if site_info.porcupine is None:
_LOGGER.debug("Loading porcupine for %s", site_info.site_id)
site_info.porcupine = pvporcupine.create(
access_key=self.access_key,
keyword_paths=[str(kw) for kw in self.model_ids],
model_path=self.model_path,
sensitivities=self.sensitivities,
)

Expand Down
13 changes: 12 additions & 1 deletion rhasspywake_porcupine_hermes/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@
def main():
"""Main method."""
parser = argparse.ArgumentParser(prog="rhasspy-wake-porcupine-hermes")
parser.add_argument(
"--access-key",
required=True,
help="Porcupine access key",
)
parser.add_argument(
"--keyword",
required=True,
Expand All @@ -41,6 +46,11 @@ def main():
action="append",
help="Wakeword IDs of each keyword (default: use file name)",
)
parser.add_argument(
"--model",
help="Absolute path to the file containing model parameters (.pv)"
"Default: using the library provided by `pvporcupine`"
)
parser.add_argument(
"--sensitivity",
action="append",
Expand Down Expand Up @@ -69,7 +79,6 @@ def main():

# --- DEPRECATED (using pvporcupine now) ---
parser.add_argument("--library", help="Path to Porcupine shared library (.so)")
parser.add_argument("--model", help="Path to Porcupine model (.pv)")
# --- DEPRECATED (using pvporcupine now) ---

hermes_cli.add_hermes_args(parser)
Expand Down Expand Up @@ -164,6 +173,7 @@ def main():
client = mqtt.Client()
hermes = WakeHermesMqtt(
client,
args.access_key,
args.keyword,
keyword_names,
sensitivities,
Expand All @@ -173,6 +183,7 @@ def main():
udp_forward_mqtt=args.udp_forward_mqtt,
site_ids=args.site_id,
lang=args.lang,
model_path=args.model,
)

_LOGGER.debug("Connecting to %s:%s", args.host, args.port)
Expand Down