diff --git a/configurations/homie/modules/home-assistant/assist.nix b/configurations/homie/modules/home-assistant/assist.nix index e30c9c3b..e259f589 100644 --- a/configurations/homie/modules/home-assistant/assist.nix +++ b/configurations/homie/modules/home-assistant/assist.nix @@ -62,7 +62,12 @@ uri = "tcp://127.0.0.1:10400"; threshold = 0.55; + vadThreshold = 0.50; + customModelsDirectories = ["${wakewords-src}/en/yo_homie"]; + preloadModels = ["yo_homie"]; + + extraArgs = ["--debug"]; }; }; diff --git a/modules/wyoming-plus/default.nix b/modules/wyoming-plus/default.nix index f5e10004..8a9abbd3 100644 --- a/modules/wyoming-plus/default.nix +++ b/modules/wyoming-plus/default.nix @@ -4,13 +4,20 @@ pkgs, ... }: let + inherit (lib) getExe mkOption types; inherit (lib.modules) mkForce mkIf mkOverride; - inherit (lib.strings) concatMapStringsSep concatStringsSep optionalString; + inherit (lib.strings) concatMapStringsSep concatStringsSep; cfg = config.services.wyoming; in { + options.services.wyoming.openwakeword.vadThreshold = mkOption { + type = types.float; + default = 0.0; + apply = toString; + }; + config = let - forkedPkg = (import ./pkgs {inherit pkgs;}).wyoming-openwakeword; + forkedPkg = pkgs.callPackage ./pkgs {}; in { systemd.services = mkIf (cfg.openwakeword.enable) { wyoming-openwakeword.serviceConfig = { @@ -18,26 +25,22 @@ in { # changes according to https://github.com/rhasspy/wyoming-openwakeword/pull/27 ExecStart = mkForce (concatStringsSep " " [ - "${cfg.openwakeword.package}/bin/wyoming-openwakeword" + (getExe cfg.openwakeword.package) "--uri ${cfg.openwakeword.uri}" "--threshold ${cfg.openwakeword.threshold}" + "--vad-threshold ${cfg.openwakeword.vadThreshold}" + "--trigger-level ${cfg.openwakeword.triggerLevel}" (concatMapStringsSep " " (dir: "--custom-model-dir ${toString dir}") cfg.openwakeword.customModelsDirectories) - # removed option https://github.com/rhasspy/wyoming-openwakeword/pull/27#issuecomment-2211822998 - (optionalString - (cfg.openwakeword.package != forkedPkg) - (concatMapStringsSep " " (model: "--preload-model ${model}") cfg.openwakeword.preloadModels)) + (concatMapStringsSep " " + (model: "--preload-model ${model}") + cfg.openwakeword.preloadModels) - # removed option since preloading was removed - (optionalString - (cfg.openwakeword.package != forkedPkg) - "--trigger-level ${cfg.openwakeword.triggerLevel}") - - "${cfg.openwakeword.extraArgs}" + cfg.openwakeword.extraArgs ]); }; }; diff --git a/modules/wyoming-plus/pkgs/default.nix b/modules/wyoming-plus/pkgs/default.nix index 9e2f785e..9713d4c9 100644 --- a/modules/wyoming-plus/pkgs/default.nix +++ b/modules/wyoming-plus/pkgs/default.nix @@ -1,19 +1,38 @@ -{pkgs, ...}: let - python3Packages = pkgs.python311Packages; -in rec { - speexdsp-ns = pkgs.callPackage ./speexdsp-ns.nix { - inherit python3Packages; - }; +{ + lib, + fetchFromGitHub, + onnxruntime, + python3Packages, + wyoming-openwakeword, + ... +}: let + inherit (lib) makeLibraryPath; +in + wyoming-openwakeword.overridePythonAttrs (o: { + version = o.version + "-vad"; - tflite-runtime = pkgs.callPackage ./tflite-runtime.nix { - inherit python3Packages; - }; + # https://github.com/rhasspy/wyoming-openwakeword/pull/17 + src = fetchFromGitHub { + owner = "rhasspy"; + repo = "wyoming-openwakeword"; + rev = "8e679a592f5862d67a7b688d3f711b468e4b1f93"; + hash = "sha256-sP0i2ghcTpuuZbVTsAFw527y2oaJIH9OolQtKjkYC2E="; + }; - openwakeword = pkgs.callPackage ./openwakeword.nix { - inherit python3Packages speexdsp-ns tflite-runtime; - }; + buildInputs = + (o.buildInputs or []) + ++ [onnxruntime]; - wyoming-openwakeword = pkgs.callPackage ./wyoming-openwakeword.nix { - inherit openwakeword python3Packages; - }; -} + propagatedBuildInputs = + (o.propagatedBuildInputs or []) + ++ [python3Packages.onnxruntime]; + + # Native onnxruntime lib used by Python module onnxruntime can't find its other libs without this + makeWrapperArgs = [ + ''--prefix LD_LIBRARY_PATH : "${makeLibraryPath [onnxruntime]}"'' + ]; + + postFixup = '' + cp -ar ./wyoming_openwakeword/models/silero_vad.onnx $out/lib/python*/site-packages/wyoming_openwakeword/models + ''; + }) diff --git a/modules/wyoming-plus/pkgs/openwakeword.nix b/modules/wyoming-plus/pkgs/openwakeword.nix deleted file mode 100644 index 02b1d3df..00000000 --- a/modules/wyoming-plus/pkgs/openwakeword.nix +++ /dev/null @@ -1,41 +0,0 @@ -{ - fetchFromGitHub, - python3Packages, - speexdsp-ns, - tflite-runtime, - ... -}: let - inherit (builtins) attrValues; -in - python3Packages.buildPythonApplication rec { - pname = "openwakeword"; - version = "0.6.0"; - pyproject = true; - - src = fetchFromGitHub { - owner = "dscripka"; - repo = "openWakeWord"; - rev = "v${version}"; - hash = "sha256-QsXV9REAHdP0Y0fVZuU+Gt9+gcPMB60bc3DOMDYuaDM="; - }; - - nativeBuildInputs = with python3Packages; [ - setuptools - ]; - - propagatedBuildInputs = attrValues { - inherit - (python3Packages) - onnxruntime - tqdm - scipy - scikit-learn - requests - ; - - inherit - speexdsp-ns - tflite-runtime - ; - }; - } diff --git a/modules/wyoming-plus/pkgs/speexdsp-ns.nix b/modules/wyoming-plus/pkgs/speexdsp-ns.nix deleted file mode 100644 index 93e687d4..00000000 --- a/modules/wyoming-plus/pkgs/speexdsp-ns.nix +++ /dev/null @@ -1,21 +0,0 @@ -{ - fetchFromGitHub, - python3Packages, - speexdsp, - swig, - ... -}: -python3Packages.buildPythonApplication { - pname = "speexdsp-ns"; - version = "0.1.2"; - - src = fetchFromGitHub { - owner = "TeaPoly"; - repo = "speexdsp-ns-python"; - rev = "8af784a230e23f4eeaa4a58111774ad0864b1f0b"; - hash = "sha256-9IGhHZBlDYfGygB+fAdEDp7qeIEOWBsiLZAUFTVBxG0="; - }; - - nativeBuildInputs = [swig]; - propagatedBuildInputs = [speexdsp]; -} diff --git a/modules/wyoming-plus/pkgs/tflite-runtime.nix b/modules/wyoming-plus/pkgs/tflite-runtime.nix deleted file mode 100644 index 060d7d37..00000000 --- a/modules/wyoming-plus/pkgs/tflite-runtime.nix +++ /dev/null @@ -1,15 +0,0 @@ -{ - fetchurl, - python3Packages, - ... -}: -python3Packages.buildPythonApplication { - pname = "tflite-runtime"; - format = "wheel"; - version = "2.14.0"; - - src = fetchurl { - url = "https://files.pythonhosted.org/packages/8f/a6/02d68cb62cd221589a0ff055073251d883936237c9c990e34a1d7cecd06f/tflite_runtime-2.14.0-cp311-cp311-manylinux2014_x86_64.whl"; - hash = "sha256-GVq3UuflcymmjlTdPdVDn62Ii5v/G+Dw3AQqMjepDk0="; - }; -} diff --git a/modules/wyoming-plus/pkgs/wyoming-openwakeword.nix b/modules/wyoming-plus/pkgs/wyoming-openwakeword.nix deleted file mode 100644 index 2215993a..00000000 --- a/modules/wyoming-plus/pkgs/wyoming-openwakeword.nix +++ /dev/null @@ -1,62 +0,0 @@ -/* -This package uses a `wyoming-openwakeword` fork that makes use of -the upstream `openwakeword` instead of a fork: https://github.com/rhasspy/wyoming-openwakeword/pull/27 -*/ -{ - lib, - fetchFromGitHub, - onnxruntime, - openwakeword, - python3Packages, - ... -}: let - inherit (lib) attrValues makeLibraryPath; -in - python3Packages.buildPythonApplication { - pname = "wyoming-openwakeword"; - version = "1.10.0-unstable"; - pyproject = true; - - src = fetchFromGitHub { - owner = "rhasspy"; - repo = "wyoming-openwakeword"; - rev = "324d669645a778439c5392d9e287a763ead3cf4c"; - hash = "sha256-69oR2LHiUfx8j39nWp7XhG5xTvmOoPCLjSlH1CFvavo="; - }; - - nativeBuildInputs = attrValues { - inherit - (python3Packages) - setuptools - ; - }; - - pythonRelaxDeps = [ - "wyoming" - ]; - - propagatedBuildInputs = attrValues { - inherit - (python3Packages) - wyoming - ; - - inherit openwakeword; - }; - - pythonImportsCheck = [ - "wyoming_openwakeword" - ]; - - # Native onnxruntime lib used by Python module onnxruntime can't find its other libs without this - makeWrapperArgs = [ - ''--prefix LD_LIBRARY_PATH : "${makeLibraryPath [onnxruntime]}"'' - ]; - - meta = { - description = "Open source voice assistant toolkit for many human languages"; - homepage = "https://github.com/rhasspy/wyoming-openwakeword"; - license = lib.licenses.mit; - mainProgram = "wyoming-openwakeword"; - }; - }