From c75cb0759da653d4e3da279af95d1eb196a040f6 Mon Sep 17 00:00:00 2001 From: matt1432 Date: Sun, 15 Dec 2024 17:14:49 -0500 Subject: [PATCH] refactor(wyoming): move to tflite dep instead of tensorflow --- nixosModules/wyoming-plus/default.nix | 2 +- nixosModules/wyoming-plus/pkgs/default.nix | 19 ++++++ .../wyoming-plus/pkgs/openwakeword.nix | 66 +++++++++---------- .../wyoming-plus/pkgs/tflite-runtime.nix | 15 +++++ .../pkgs/wyoming-openwakeword.nix | 66 +++++++++++++------ 5 files changed, 114 insertions(+), 54 deletions(-) create mode 100644 nixosModules/wyoming-plus/pkgs/default.nix create mode 100644 nixosModules/wyoming-plus/pkgs/tflite-runtime.nix diff --git a/nixosModules/wyoming-plus/default.nix b/nixosModules/wyoming-plus/default.nix index d92a7d71..f5e10004 100644 --- a/nixosModules/wyoming-plus/default.nix +++ b/nixosModules/wyoming-plus/default.nix @@ -10,7 +10,7 @@ cfg = config.services.wyoming; in { config = let - forkedPkg = import ./pkgs/wyoming-openwakeword.nix pkgs; + forkedPkg = (import ./pkgs {inherit pkgs;}).wyoming-openwakeword; in { systemd.services = mkIf (cfg.openwakeword.enable) { wyoming-openwakeword.serviceConfig = { diff --git a/nixosModules/wyoming-plus/pkgs/default.nix b/nixosModules/wyoming-plus/pkgs/default.nix new file mode 100644 index 00000000..9e2f785e --- /dev/null +++ b/nixosModules/wyoming-plus/pkgs/default.nix @@ -0,0 +1,19 @@ +{pkgs, ...}: let + python3Packages = pkgs.python311Packages; +in rec { + speexdsp-ns = pkgs.callPackage ./speexdsp-ns.nix { + inherit python3Packages; + }; + + tflite-runtime = pkgs.callPackage ./tflite-runtime.nix { + inherit python3Packages; + }; + + openwakeword = pkgs.callPackage ./openwakeword.nix { + inherit python3Packages speexdsp-ns tflite-runtime; + }; + + wyoming-openwakeword = pkgs.callPackage ./wyoming-openwakeword.nix { + inherit openwakeword python3Packages; + }; +} diff --git a/nixosModules/wyoming-plus/pkgs/openwakeword.nix b/nixosModules/wyoming-plus/pkgs/openwakeword.nix index 0a78be48..02b1d3df 100644 --- a/nixosModules/wyoming-plus/pkgs/openwakeword.nix +++ b/nixosModules/wyoming-plus/pkgs/openwakeword.nix @@ -1,43 +1,41 @@ { fetchFromGitHub, - fetchpatch, python3Packages, speexdsp-ns, + tflite-runtime, ... -}: -python3Packages.buildPythonApplication rec { - pname = "openwakeword"; - version = "0.6.0"; - pyproject = true; +}: 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="; - }; + src = fetchFromGitHub { + owner = "dscripka"; + repo = "openWakeWord"; + rev = "v${version}"; + hash = "sha256-QsXV9REAHdP0Y0fVZuU+Gt9+gcPMB60bc3DOMDYuaDM="; + }; - # Patch upstream to enable use of full tensorflow dep - pythonRemoveDeps = ["tflite-runtime"]; - patches = [ - (fetchpatch { - url = "https://github.com/dscripka/openWakeWord/pull/178/commits/99cd87e8898348255e864540e43bab17ce0576d6.patch"; - hash = "sha256-xveMBZTcYfT8LKiiStqYjjOdUOM/v4taQzSewo97Bfc="; - }) - ]; + nativeBuildInputs = with python3Packages; [ + setuptools + ]; - nativeBuildInputs = with python3Packages; [ - setuptools - ]; + propagatedBuildInputs = attrValues { + inherit + (python3Packages) + onnxruntime + tqdm + scipy + scikit-learn + requests + ; - propagatedBuildInputs = - (with python3Packages; [ - onnxruntime - tensorflow-bin - tqdm - scipy - scikit-learn - requests - ]) - ++ [speexdsp-ns]; -} + inherit + speexdsp-ns + tflite-runtime + ; + }; + } diff --git a/nixosModules/wyoming-plus/pkgs/tflite-runtime.nix b/nixosModules/wyoming-plus/pkgs/tflite-runtime.nix new file mode 100644 index 00000000..060d7d37 --- /dev/null +++ b/nixosModules/wyoming-plus/pkgs/tflite-runtime.nix @@ -0,0 +1,15 @@ +{ + 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/nixosModules/wyoming-plus/pkgs/wyoming-openwakeword.nix b/nixosModules/wyoming-plus/pkgs/wyoming-openwakeword.nix index 71399e46..2453e2d4 100644 --- a/nixosModules/wyoming-plus/pkgs/wyoming-openwakeword.nix +++ b/nixosModules/wyoming-plus/pkgs/wyoming-openwakeword.nix @@ -2,28 +2,56 @@ 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 */ -pkgs: let - pyPkgs = pkgs.python312Packages; - - speexdsp-ns = pkgs.callPackage ./speexdsp-ns.nix { - python3Packages = pyPkgs; - }; - - openwakeword = pkgs.callPackage ./openwakeword.nix { - inherit speexdsp-ns; - python3Packages = pyPkgs; - }; +{ + fetchFromGitHub, + lib, + openwakeword, + python3Packages, + ... +}: let + inherit (lib) attrValues; in - (pkgs.wyoming-openwakeword.override { - python3Packages = pyPkgs; - }) - .overrideAttrs (o: { - src = pkgs.fetchFromGitHub { + python3Packages.buildPythonApplication { + pname = "wyoming-openwakeword"; + version = "1.10.0-unstable"; + pyproject = true; + + src = fetchFromGitHub { owner = "rhasspy"; repo = "wyoming-openwakeword"; - rev = "synesthesiam-20240627-openwakeword"; + # rev = "synesthesiam-20240627-openwakeword"; + rev = "324d669645a778439c5392d9e287a763ead3cf4c"; hash = "sha256-69oR2LHiUfx8j39nWp7XhG5xTvmOoPCLjSlH1CFvavo="; }; - propagatedBuildInputs = [openwakeword pyPkgs.wyoming]; - }) + nativeBuildInputs = attrValues { + inherit + (python3Packages) + setuptools + ; + }; + + pythonRelaxDeps = [ + "wyoming" + ]; + + propagatedBuildInputs = attrValues { + inherit + (python3Packages) + wyoming + ; + + inherit openwakeword; + }; + + pythonImportsCheck = [ + "wyoming_openwakeword" + ]; + + 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"; + }; + }