voice: default wake word to "Hey Computer", capture command after a pause
openWakeWord ships no "computer" model, so pin a community openWakeWord-compatible ONNX (Apache-2.0, sha256 in pins.json `wake_word`) and fetch it into .runtime/voice/wake from scripts/voice-models.py. Its scores run lower than the official models (~0.26-0.82 on the phrase, <0.02 on negatives), so the seeded wake.threshold is 0.2 (the official models score ~0.99 at 0.5). Also fix command capture: after the wake word the daemon now waits listen_timeout_s (default 3s) for the command's speech to begin instead of assuming it is glued to the wake word, so a natural pause while the cue beep plays no longer truncates the command.
This commit is contained in:
1 parent
ae37abbc3f
commit
ec39a990e4
7 files changed
+218
-29
No files matched your search
+58
-9
@@ -6,9 +6,12 @@ Run after installing `requirements/voice.txt` (bootstrap does this with
|
||||
`gateway.voice` from config.json so the downloaded models match the configured
|
||||
names, or take explicit flags.
|
||||
|
||||
- **Wake word** (openWakeWord): downloaded by `openwakeword.utils.download_models`
|
||||
into the venv's package resources dir (inside `.runtime/venv/`, so still
|
||||
contained in the checkout). The detector resolves the model by name there.
|
||||
- **Wake word** (openWakeWord): official models are downloaded by
|
||||
`openwakeword.utils.download_models` into the venv's package resources dir
|
||||
(inside `.runtime/venv/`, so still contained in the checkout); the detector
|
||||
resolves the model by name there. A **pinned community model** (openWakeWord
|
||||
ships no "computer" model) is fetched from `pins.json` `wake_word` into the
|
||||
configured `model_dir` (`.runtime/voice/wake`) and verified by sha256.
|
||||
- **TTS** (Piper): the voice `.onnx` + `.onnx.json` are fetched from the
|
||||
`rhasspy/piper-voices` HF repo into `.runtime/voice/tts/`.
|
||||
- **STT** (faster-whisper): instantiating the model warms it into the HF cache
|
||||
@@ -18,12 +21,15 @@ names, or take explicit flags.
|
||||
from __future__ import annotations
|
||||
|
||||
import argparse
|
||||
import hashlib
|
||||
import json
|
||||
import shutil
|
||||
import urllib.request
|
||||
from pathlib import Path
|
||||
|
||||
REPO_ROOT = Path(__file__).resolve().parent.parent
|
||||
RUNTIME = REPO_ROOT / ".runtime" / "voice"
|
||||
PINS = REPO_ROOT / "pins.json"
|
||||
PIPER_REPO = "rhasspy/piper-voices"
|
||||
|
||||
|
||||
@@ -42,15 +48,56 @@ def piper_hf_path(voice: str) -> str:
|
||||
return f"{lang}/{locale}/{name}/{quality}/{voice}.onnx"
|
||||
|
||||
|
||||
def download_wake(name: str) -> None:
|
||||
def pinned_wake_models() -> dict:
|
||||
"""Return the code-owned wake-word refs from `pins.json` (`name` -> ref)."""
|
||||
try:
|
||||
pins = json.loads(PINS.read_text())
|
||||
except Exception:
|
||||
return {}
|
||||
block = pins.get("wake_word", {}) or {}
|
||||
return {
|
||||
name: ref
|
||||
for name, ref in block.items()
|
||||
if isinstance(ref, dict) and ref.get("url")
|
||||
}
|
||||
|
||||
|
||||
def _sha256(path: Path) -> str:
|
||||
return hashlib.sha256(path.read_bytes()).hexdigest()
|
||||
|
||||
|
||||
def download_wake_file(name: str, ref: dict, target_dir: Path) -> None:
|
||||
"""Fetch a pinned community wake model into `target_dir`, verifying sha256."""
|
||||
url = str(ref["url"])
|
||||
expected = str(ref.get("sha256", "") or "")
|
||||
target_dir.mkdir(parents=True, exist_ok=True)
|
||||
dest = target_dir / f"{name}.onnx"
|
||||
if dest.is_file() and (not expected or _sha256(dest) == expected):
|
||||
print(f"== wake word: {dest.name} (present)")
|
||||
return
|
||||
print(f"== wake word: {url} -> {dest}")
|
||||
with urllib.request.urlopen(url) as resp: # pinned https URL from pins.json
|
||||
data = resp.read()
|
||||
if expected and hashlib.sha256(data).hexdigest() != expected:
|
||||
raise SystemExit(f"sha256 mismatch for {name}: refusing to write {dest}")
|
||||
dest.write_bytes(data)
|
||||
|
||||
|
||||
def download_wake(name: str, target_dir: Path) -> None:
|
||||
import openwakeword.utils as utils
|
||||
|
||||
print(f"== wake word model: {name}")
|
||||
# Default target: the venv's package resources dir (inside .runtime/venv).
|
||||
# openWakeWord resolves the model (and its shared mel/embedding models) by
|
||||
# name from there.
|
||||
# Always fetch the shared feature (mel/embedding) + VAD models, and for an
|
||||
# official name the phrase model itself, into the venv's package resources
|
||||
# dir (inside .runtime/venv). An unknown name is skipped here.
|
||||
utils.download_models(model_names=[name])
|
||||
|
||||
# A pinned community model (openWakeWord ships no "computer" model) is
|
||||
# fetched into the configured model_dir so the detector resolves it by path.
|
||||
ref = pinned_wake_models().get(name)
|
||||
if ref:
|
||||
download_wake_file(name, ref, target_dir)
|
||||
|
||||
|
||||
def download_voice(voice: str, target: Path) -> None:
|
||||
from huggingface_hub import hf_hub_download
|
||||
@@ -86,6 +133,8 @@ def main(argv: list[str] | None = None) -> int:
|
||||
parser = argparse.ArgumentParser(description=__doc__)
|
||||
parser.add_argument("--config", default=str(REPO_ROOT / "config.json"))
|
||||
parser.add_argument("--wake", default=None, help="openWakeWord model name")
|
||||
parser.add_argument("--wake-dir", default=str(RUNTIME / "wake"),
|
||||
help="target dir for a pinned community wake model")
|
||||
parser.add_argument("--stt", default=None, help="faster-whisper model size/path")
|
||||
parser.add_argument("--tts", default=None, help="Piper voice id")
|
||||
parser.add_argument("--tts-dir", default=str(RUNTIME / "tts"))
|
||||
@@ -95,12 +144,12 @@ def main(argv: list[str] | None = None) -> int:
|
||||
args = parser.parse_args(argv)
|
||||
|
||||
voice_cfg = _config_voice(Path(args.config))
|
||||
wake = args.wake or (voice_cfg.get("wake", {}) or {}).get("model") or "hey_mycroft"
|
||||
wake = args.wake or (voice_cfg.get("wake", {}) or {}).get("model") or "hey_computer"
|
||||
stt = args.stt or (voice_cfg.get("stt", {}) or {}).get("model") or "base.en"
|
||||
tts = args.tts or (voice_cfg.get("tts", {}) or {}).get("voice") or "en_US-lessac-medium"
|
||||
|
||||
if not args.skip_wake:
|
||||
download_wake(wake)
|
||||
download_wake(wake, Path(args.wake_dir))
|
||||
if not args.skip_tts:
|
||||
download_voice(tts, Path(args.tts_dir))
|
||||
if not args.skip_stt:
|
||||
|
||||
Reference in new issue
Block a user