From cf1c78a7d4276e83038d30281d783920cd9f1808 Mon Sep 17 00:00:00 2001 From: Martin Weinelt Date: Fri, 9 Jun 2023 18:57:11 +0200 Subject: [PATCH 1/8] ctranslate2: init at 3.15.1 Fast inference engine for Transformer models. --- .../libraries/ctranslate2/default.nix | 59 +++++++++++++++++++ pkgs/top-level/all-packages.nix | 2 + 2 files changed, 61 insertions(+) create mode 100644 pkgs/development/libraries/ctranslate2/default.nix diff --git a/pkgs/development/libraries/ctranslate2/default.nix b/pkgs/development/libraries/ctranslate2/default.nix new file mode 100644 index 000000000000..cdfbcc3ebcc7 --- /dev/null +++ b/pkgs/development/libraries/ctranslate2/default.nix @@ -0,0 +1,59 @@ +{ lib +, stdenv +, fetchFromGitHub +, cmake +, darwin # Accelerate +, llvmPackages # openmp +, oneDNN +, openblas +, withMkl ? false, mkl +}: + +let + cmakeBool = b: if b then "ON" else "OFF"; +in +stdenv.mkDerivation rec { + pname = "ctranslate2"; + version = "3.15.1"; + + src = fetchFromGitHub { + owner = "OpenNMT"; + repo = "CTranslate2"; + rev = "v${version}"; + hash = "sha256-lh4j53+LQj09tq3qiHrL2YrACzWY1V/HX8Ixnq0TTyY="; + fetchSubmodules = true; + }; + + nativeBuildInputs = [ + cmake + ]; + + cmakeFlags = [ + # https://opennmt.net/CTranslate2/installation.html#build-options + "-DWITH_DNNL=OFF" # requires oneDNN>=3.0 + "-DWITH_OPENBLAS=ON" + "-DWITH_MKL=${cmakeBool withMkl}" + ] + ++ lib.optional stdenv.isDarwin "-DWITH_ACCELERATE=ON"; + + buildInputs = [ + llvmPackages.openmp + openblas + oneDNN + ] ++ lib.optional withMkl [ + mkl + ] ++ lib.optionals stdenv.isDarwin [ + darwin.apple_sdk.frameworks.Accelerate + ] ++ lib.optionals (stdenv.isDarwin && stdenv.isx86_64) [ + darwin.apple_sdk.frameworks.CoreGraphics + darwin.apple_sdk.frameworks.CoreVideo + ]; + + meta = with lib; { + description = "Fast inference engine for Transformer models"; + homepage = "https://github.com/OpenNMT/CTranslate2"; + changelog = "https://github.com/OpenNMT/CTranslate2/blob/${src.rev}/CHANGELOG.md"; + license = licenses.mit; + maintainers = with maintainers; [ hexa ]; + }; +} diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index e78a7e4b30fc..adea606aa109 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -20152,6 +20152,8 @@ with pkgs; cpp-jwt = callPackage ../development/libraries/cpp-jwt { }; + ctranslate2 = callPackage ../development/libraries/ctranslate2 { }; + ubus = callPackage ../development/libraries/ubus { }; uci = callPackage ../development/libraries/uci { }; From 32f6c393a109457ca464754946b8128c2d71d7ec Mon Sep 17 00:00:00 2001 From: Martin Weinelt Date: Fri, 9 Jun 2023 19:25:30 +0200 Subject: [PATCH 2/8] python310Packages.ctranslate2: init at 3.15.1 Python bindings for ctranslate2. --- .../python-modules/ctranslate2/default.nix | 84 +++++++++++++++++++ pkgs/top-level/python-packages.nix | 4 + 2 files changed, 88 insertions(+) create mode 100644 pkgs/development/python-modules/ctranslate2/default.nix diff --git a/pkgs/development/python-modules/ctranslate2/default.nix b/pkgs/development/python-modules/ctranslate2/default.nix new file mode 100644 index 000000000000..4cbf0ecd7124 --- /dev/null +++ b/pkgs/development/python-modules/ctranslate2/default.nix @@ -0,0 +1,84 @@ +{ lib +, buildPythonPackage + +# build-system +, pybind11 +, setuptools + +# dependencies +, ctranslate2-cpp +, numpy +, pyyaml + +# tests +, pytestCheckHook +, tensorflow +, torch +, transformers +, wurlitzer +}: + +buildPythonPackage rec { + inherit (ctranslate2-cpp) pname version src; + format = "setuptools"; + + # https://github.com/OpenNMT/CTranslate2/tree/master/python + sourceRoot = "source/python"; + + nativeBuildInputs = [ + pybind11 + setuptools + ]; + + buildInputs = [ + ctranslate2-cpp + ]; + + propagatedBuildInputs = [ + numpy + pyyaml + ]; + + pythonImportsCheck = [ + # https://opennmt.net/CTranslate2/python/overview.html + "ctranslate2" + "ctranslate2.converters" + "ctranslate2.models" + "ctranslate2.specs" + ]; + + nativeCheckInputs = [ + pytestCheckHook + tensorflow + torch + transformers + wurlitzer + ]; + + preCheck = '' + # run tests against build result, not sources + rm -rf ctranslate2 + + export HOME=$TMPDIR + ''; + + disabledTests = [ + # AssertionError: assert 'int8' in {'float32'} + "test_get_supported_compute_types" + ]; + + disabledTestPaths = [ + # TODO: ModuleNotFoundError: No module named 'opennmt' + "tests/test_opennmt_tf.py" + # OSError: We couldn't connect to 'https://huggingface.co' to load this file + "tests/test_transformers.py" + ]; + + meta = with lib; { + description = "Fast inference engine for Transformer models"; + homepage = "https://github.com/OpenNMT/CTranslate2"; + changelog = "https://github.com/OpenNMT/CTranslate2/blob/${src.rev}/CHANGELOG.md"; + license = licenses.mit; + maintainers = with maintainers; [ hexa ]; + }; +} diff --git a/pkgs/top-level/python-packages.nix b/pkgs/top-level/python-packages.nix index b9051f34031d..36a081dd6f0a 100644 --- a/pkgs/top-level/python-packages.nix +++ b/pkgs/top-level/python-packages.nix @@ -2218,6 +2218,10 @@ self: super: with self; { ctap-keyring-device = callPackage ../development/python-modules/ctap-keyring-device { }; + ctranslate2 = callPackage ../development/python-modules/ctranslate2 { + ctranslate2-cpp = pkgs.ctranslate2; + }; + cu2qu = callPackage ../development/python-modules/cu2qu { }; cucumber-tag-expressions = callPackage ../development/python-modules/cucumber-tag-expressions { }; From 9d1d140acfad806f5768d4e5d276b55a3a4c50b0 Mon Sep 17 00:00:00 2001 From: Martin Weinelt Date: Fri, 9 Jun 2023 20:08:55 +0200 Subject: [PATCH 3/8] python310Packages.faster-whisper: init at 0.6.0 Faster Whisper transcription with CTranslate2 --- .../python-modules/faster-whisper/default.nix | 63 +++++++++++++++++++ pkgs/top-level/python-packages.nix | 2 + 2 files changed, 65 insertions(+) create mode 100644 pkgs/development/python-modules/faster-whisper/default.nix diff --git a/pkgs/development/python-modules/faster-whisper/default.nix b/pkgs/development/python-modules/faster-whisper/default.nix new file mode 100644 index 000000000000..86529151e91c --- /dev/null +++ b/pkgs/development/python-modules/faster-whisper/default.nix @@ -0,0 +1,63 @@ +{ lib +, buildPythonPackage +, fetchFromGitHub + +# dependencies +, av +, ctranslate2 +, huggingface-hub +, onnxruntime +, tokenizers + +# tests +, pytestCheckHook +}: + +buildPythonPackage rec { + pname = "faster-whisper"; + version = "0.6.0"; + format = "setuptools"; + + src = fetchFromGitHub { + owner = "guillaumekln"; + repo = "faster-whisper"; + rev = "v${version}"; + hash = "sha256-tBajxrAhV7R9VnAzUr7ONAYH9h8Uh/UUeu2YZAAotBo="; + }; + + postPatch = '' + substituteInPlace requirements.txt \ + --replace "onnxruntime>=1.14,<2" "onnxruntime" + ''; + + propagatedBuildInputs = [ + av + ctranslate2 + huggingface-hub + onnxruntime + tokenizers + ]; + + pythonImportsCheck = [ + "faster_whisper" + ]; + + # all tests require downloads + doCheck = false; + + nativeCheckInputs = [ + pytestCheckHook + ]; + + preCheck = '' + export HOME=$TMPDIR + ''; + + meta = with lib; { + changelog = "https://github.com/guillaumekln/faster-whisper/releases/tag/v${version}"; + description = "Faster Whisper transcription with CTranslate2"; + homepage = "https://github.com/guillaumekln/faster-whisper"; + license = licenses.mit; + maintainers = with maintainers; [ hexa ]; + }; +} diff --git a/pkgs/top-level/python-packages.nix b/pkgs/top-level/python-packages.nix index 36a081dd6f0a..278b47fdcd8d 100644 --- a/pkgs/top-level/python-packages.nix +++ b/pkgs/top-level/python-packages.nix @@ -3490,6 +3490,8 @@ self: super: with self; { fastentrypoints = callPackage ../development/python-modules/fastentrypoints { }; + faster-whisper = callPackage ../development/python-modules/faster-whisper { }; + fastimport = callPackage ../development/python-modules/fastimport { }; fastjet = toPythonModule (pkgs.fastjet.override { From 3e235f99b9ce612aae9abb89cdd2920d6d56f021 Mon Sep 17 00:00:00 2001 From: Martin Weinelt Date: Fri, 9 Jun 2023 17:46:46 +0200 Subject: [PATCH 4/8] wyoming-piper: init at 0.0.3 Wyoming Server for Piper, a fast local neural TTS system. --- .../audio/wyoming/piper-entrypoint.patch | 30 +++++++++++++++ pkgs/tools/audio/wyoming/piper.nix | 37 +++++++++++++++++++ pkgs/top-level/all-packages.nix | 2 + 3 files changed, 69 insertions(+) create mode 100644 pkgs/tools/audio/wyoming/piper-entrypoint.patch create mode 100644 pkgs/tools/audio/wyoming/piper.nix diff --git a/pkgs/tools/audio/wyoming/piper-entrypoint.patch b/pkgs/tools/audio/wyoming/piper-entrypoint.patch new file mode 100644 index 000000000000..c2e4245e5b25 --- /dev/null +++ b/pkgs/tools/audio/wyoming/piper-entrypoint.patch @@ -0,0 +1,30 @@ +diff --git a/setup.py b/setup.py +index 1355313..3b144c1 100644 +--- a/setup.py ++++ b/setup.py +@@ -35,4 +35,9 @@ setup( + "Programming Language :: Python :: 3.10", + ], + keywords="rhasspy wyoming piper", ++ entry_points={ ++ 'console_scripts': [ ++ 'wyoming-piper = wyoming_piper:__main__.run' ++ ] ++ } + ) +diff --git a/wyoming_piper/__main__.py b/wyoming_piper/__main__.py +index f60cf13..a0a15f7 100755 +--- a/wyoming_piper/__main__.py ++++ b/wyoming_piper/__main__.py +@@ -143,5 +143,9 @@ async def main() -> None: + + # ----------------------------------------------------------------------------- + +-if __name__ == "__main__": ++def run(): + asyncio.run(main()) ++ ++ ++if __name__ == "__main__": ++ run() +\ No newline at end of file diff --git a/pkgs/tools/audio/wyoming/piper.nix b/pkgs/tools/audio/wyoming/piper.nix new file mode 100644 index 000000000000..830f72059653 --- /dev/null +++ b/pkgs/tools/audio/wyoming/piper.nix @@ -0,0 +1,37 @@ +{ lib +, python3 +, fetchPypi +}: + +python3.pkgs.buildPythonApplication rec { + pname = "wyoming-piper"; + version = "0.0.3"; + format = "setuptools"; + + src = fetchPypi { + pname = "wyoming_piper"; + inherit version; + hash = "sha256-vl7LjW/2HBx6o/+vpap+wSG3XXzDwFacNmcbeU/8bOs="; + }; + + patches = [ + ./piper-entrypoint.patch + ]; + + propagatedBuildInputs = with python3.pkgs; [ + wyoming + ]; + + pythonImportsCheck = [ + "wyoming_piper" + ]; + + doCheck = false; + + meta = with lib; { + description = "Wyoming Server for Piper"; + homepage = "https://pypi.org/project/wyoming-piper/"; + license = licenses.mit; + maintainers = with maintainers; [ hexa ]; + }; +} diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index adea606aa109..befc154ae6e7 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -36199,6 +36199,8 @@ with pkgs; tts = callPackage ../tools/audio/tts { }; + wyoming-piper = callPackage ../tools/audio/wyoming/piper.nix { }; + ### GAMES _1oom = callPackage ../games/1oom { }; From dd8a4a6eb8cafc5abee60a4cf4bdc1b8cd565045 Mon Sep 17 00:00:00 2001 From: Martin Weinelt Date: Fri, 9 Jun 2023 18:02:42 +0200 Subject: [PATCH 5/8] wyoming-faster-whisper: init at 0.0.3 Wyoming Server for Faster Whisper, a reimplementation of OpenAI's Whisper model using CTranslate2. --- .../wyoming/faster-whisper-entrypoint.patch | 29 ++++++++++++++ pkgs/tools/audio/wyoming/faster-whisper.nix | 40 +++++++++++++++++++ pkgs/top-level/all-packages.nix | 2 + 3 files changed, 71 insertions(+) create mode 100644 pkgs/tools/audio/wyoming/faster-whisper-entrypoint.patch create mode 100644 pkgs/tools/audio/wyoming/faster-whisper.nix diff --git a/pkgs/tools/audio/wyoming/faster-whisper-entrypoint.patch b/pkgs/tools/audio/wyoming/faster-whisper-entrypoint.patch new file mode 100644 index 000000000000..1af62cb1fe22 --- /dev/null +++ b/pkgs/tools/audio/wyoming/faster-whisper-entrypoint.patch @@ -0,0 +1,29 @@ +diff --git a/setup.py b/setup.py +index 1c0b2d2..bbff1d1 100644 +--- a/setup.py ++++ b/setup.py +@@ -35,4 +35,9 @@ setup( + "Programming Language :: Python :: 3.10", + ], + keywords="rhasspy wyoming whisper", ++ entry_points={ ++ 'console_scripts': [ ++ 'wyoming-faster-whisper = wyoming_faster_whisper:__main__.run' ++ ] ++ } + ) +diff --git a/wyoming_faster_whisper/__main__.py b/wyoming_faster_whisper/__main__.py +index 5557cc5..bb9d69f 100755 +--- a/wyoming_faster_whisper/__main__.py ++++ b/wyoming_faster_whisper/__main__.py +@@ -131,5 +131,9 @@ async def main() -> None: + + # ----------------------------------------------------------------------------- + +-if __name__ == "__main__": ++def run(): + asyncio.run(main()) ++ ++ ++if __name__ == "__main__": ++ run() diff --git a/pkgs/tools/audio/wyoming/faster-whisper.nix b/pkgs/tools/audio/wyoming/faster-whisper.nix new file mode 100644 index 000000000000..747947322345 --- /dev/null +++ b/pkgs/tools/audio/wyoming/faster-whisper.nix @@ -0,0 +1,40 @@ +{ lib +, python3 +, fetchPypi +}: + +python3.pkgs.buildPythonApplication rec { + pname = "wyoming-faster-whisper"; + version = "0.0.3"; + format = "setuptools"; + + src = fetchPypi { + pname = "wyoming_faster_whisper"; + inherit version; + hash = "sha256-uqepa70lprzV3DJK2wrNAAyZkMMJ5S86RKK716zxYU4="; + }; + + patches = [ + ./faster-whisper-entrypoint.patch + ]; + + propagatedBuildInputs = with python3.pkgs; [ + ctranslate2 + tokenizers + wyoming + ]; + + pythonImportsCheck = [ + "wyoming_faster_whisper" + ]; + + # no tests + doCheck = false; + + meta = with lib; { + description = "Wyoming Server for Faster Whisper"; + homepage = "https://pypi.org/project/wyoming-faster-whisper/"; + license = licenses.mit; + maintainers = with maintainers; [ hexa ]; + }; +} diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index befc154ae6e7..5fa294e2e1c9 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -36199,6 +36199,8 @@ with pkgs; tts = callPackage ../tools/audio/tts { }; + wyoming-faster-whisper = callPackage ../tools/audio/wyoming/faster-whisper.nix { }; + wyoming-piper = callPackage ../tools/audio/wyoming/piper.nix { }; ### GAMES From 9c67abf20ae3fb25d62cd79187b5bcc21627f531 Mon Sep 17 00:00:00 2001 From: Martin Weinelt Date: Fri, 9 Jun 2023 22:01:20 +0200 Subject: [PATCH 6/8] piper-tts: rename from larynx and also the python package piper-train from larynx-train. --- .../{larynx-train => piper-train}/default.nix | 19 +++++++++---------- .../tools/audio/{larynx => piper}/default.nix | 18 +++++++++--------- pkgs/top-level/aliases.nix | 1 + pkgs/top-level/all-packages.nix | 7 +++---- pkgs/top-level/python-aliases.nix | 1 + pkgs/top-level/python-packages.nix | 4 ++-- 6 files changed, 25 insertions(+), 25 deletions(-) rename pkgs/development/python-modules/{larynx-train => piper-train}/default.nix (64%) rename pkgs/tools/audio/{larynx => piper}/default.nix (69%) diff --git a/pkgs/development/python-modules/larynx-train/default.nix b/pkgs/development/python-modules/piper-train/default.nix similarity index 64% rename from pkgs/development/python-modules/larynx-train/default.nix rename to pkgs/development/python-modules/piper-train/default.nix index 6e31d660cca9..5cf8cdea10df 100644 --- a/pkgs/development/python-modules/larynx-train/default.nix +++ b/pkgs/development/python-modules/piper-train/default.nix @@ -1,6 +1,5 @@ -{ lib -, buildPythonPackage -, larynx +{ buildPythonPackage +, piper-tts # build , cython @@ -15,10 +14,10 @@ , torch }: -buildPythonPackage rec { - inherit (larynx) version src meta; +buildPythonPackage { + inherit (piper-tts) version src meta; - pname = "larynx-train"; + pname = "piper-train"; format = "setuptools"; sourceRoot = "source/src/python"; @@ -35,13 +34,13 @@ buildPythonPackage rec { ''; postBuild = '' - make -C larynx_train/vits/monotonic_align + make -C piper_train/vits/monotonic_align ''; postInstall = '' - export MONOTONIC_ALIGN=$out/${python.sitePackages}/larynx_train/vits/monotonic_align/monotonic_align + export MONOTONIC_ALIGN=$out/${python.sitePackages}/piper_train/vits/monotonic_align/monotonic_align mkdir -p $MONOTONIC_ALIGN - cp -v ./larynx_train/vits/monotonic_align/larynx_train/vits/monotonic_align/core.*.so $MONOTONIC_ALIGN/ + cp -v ./piper_train/vits/monotonic_align/piper_train/vits/monotonic_align/core.*.so $MONOTONIC_ALIGN/ ''; propagatedBuildInputs = [ @@ -54,7 +53,7 @@ buildPythonPackage rec { ]; pythonImportsCheck = [ - "larynx_train" + "piper_train" ]; doCheck = false; # no tests diff --git a/pkgs/tools/audio/larynx/default.nix b/pkgs/tools/audio/piper/default.nix similarity index 69% rename from pkgs/tools/audio/larynx/default.nix rename to pkgs/tools/audio/piper/default.nix index 2bc55a731a0f..df8ed3e969e7 100644 --- a/pkgs/tools/audio/larynx/default.nix +++ b/pkgs/tools/audio/piper/default.nix @@ -6,11 +6,11 @@ , espeak-ng , onnxruntime , pcaudiolib -, larynx-train +, piper-train }: let - pname = "larynx"; + pname = "piper"; version = "0.0.2"; in stdenv.mkDerivation { @@ -18,9 +18,9 @@ stdenv.mkDerivation { src = fetchFromGitHub { owner = "rhasspy"; - repo = "larynx2"; - rev = "refs/tags/v${version}"; - hash = "sha256-6SZ1T2A1DyVmBH2pJBHJdsnniRuLrI/dthRTRRyVSQQ="; + repo = "piper"; + rev = "70afec58bc131010c8993c154ff02a78d1e7b8b0"; + hash = "sha256-zTW7RGcV8Hh7G6Braf27F/8s7nNjAqagp7tmrKO10BY="; }; sourceRoot = "source/src/cpp"; @@ -45,19 +45,19 @@ stdenv.mkDerivation { runHook preInstall mkdir -p $out/bin - install -m 0755 larynx $out/bin + install -m 0755 piper $out/bin runHook postInstall ''; passthru.tests = { - inherit larynx-train; + inherit piper-train; }; meta = with lib; { - changelog = "https://github.com/rhasspy/larynx2/releases/tag/v${version}"; + changelog = "https://github.com/rhasspy/piper/releases/tag/v${version}"; description = "A fast, local neural text to speech system"; - homepage = "https://github.com/rhasspy/larynx2"; + homepage = "https://github.com/rhasspy/piper"; license = licenses.mit; maintainers = with maintainers; [ hexa ]; }; diff --git a/pkgs/top-level/aliases.nix b/pkgs/top-level/aliases.nix index bad9900d0b32..196d493c7c34 100644 --- a/pkgs/top-level/aliases.nix +++ b/pkgs/top-level/aliases.nix @@ -832,6 +832,7 @@ mapAliases ({ ### L ### + larynx = piper-tts; # Added 2023-05-09 lastfmsubmitd = throw "lastfmsubmitd was removed from nixpkgs as the project is abandoned"; # Added 2022-01-01 latinmodern-math = lmmath; letsencrypt = throw "'letsencrypt' has been renamed to/replaced by 'certbot'"; # Converted to throw 2022-02-22 diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index 5fa294e2e1c9..03c0b608da98 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -9685,10 +9685,6 @@ with pkgs; jump = callPackage ../tools/system/jump { }; - larynx = callPackage ../tools/audio/larynx { }; - - larynx-train = with python3Packages; toPythonApplication larynx-train; - latex2html = callPackage ../tools/misc/latex2html { }; lazycli = callPackage ../tools/misc/lazycli { }; @@ -11316,6 +11312,9 @@ with pkgs; pim6sd = callPackage ../servers/pim6sd { }; + piper-train = with python3Packages; toPythonApplication piper-train; + piper-tts = callPackage ../tools/audio/piper { }; + phosh = callPackage ../applications/window-managers/phosh { }; phosh-mobile-settings = callPackage ../applications/window-managers/phosh/phosh-mobile-settings.nix { }; diff --git a/pkgs/top-level/python-aliases.nix b/pkgs/top-level/python-aliases.nix index 41c1b5b69cb3..e5edb721f1a3 100644 --- a/pkgs/top-level/python-aliases.nix +++ b/pkgs/top-level/python-aliases.nix @@ -158,6 +158,7 @@ mapAliases ({ jupyter_server = jupyter-server; # added 2023-01-05 Kajiki = kajiki; # added 2023-02-19 Keras = keras; # added 2021-11-25 + larynx-train = piper-train; # added 2023-06-09 ldap = python-ldap; # added 2022-09-16 lammps-cython = throw "lammps-cython no longer builds and is unmaintained"; # added 2021-07-04 logilab_astng = throw "logilab-astng has not been released since 2013 and is unmaintained"; # added 2022-11-29 diff --git a/pkgs/top-level/python-packages.nix b/pkgs/top-level/python-packages.nix index 278b47fdcd8d..a4c23b75973b 100644 --- a/pkgs/top-level/python-packages.nix +++ b/pkgs/top-level/python-packages.nix @@ -5536,8 +5536,6 @@ self: super: with self; { lark = callPackage ../development/python-modules/lark { }; - larynx-train = callPackage ../development/python-modules/larynx-train { }; - laspy = callPackage ../development/python-modules/laspy { }; laszip = callPackage ../development/python-modules/laszip { }; @@ -7643,6 +7641,8 @@ self: super: with self; { pipenv-poetry-migrate = callPackage ../development/python-modules/pipenv-poetry-migrate { }; + piper-train = callPackage ../development/python-modules/piper-train { }; + pip-api = callPackage ../development/python-modules/pip-api { }; pip-tools = callPackage ../development/python-modules/pip-tools { }; From 7f17f8da9fc7ee2aeccf0b535b4d492b58219752 Mon Sep 17 00:00:00 2001 From: Martin Weinelt Date: Fri, 9 Jun 2023 22:54:11 +0200 Subject: [PATCH 7/8] nixos/wyoming/piper: init --- nixos/modules/module-list.nix | 1 + .../modules/services/audio/wyoming/piper.nix | 174 ++++++++++++++++++ 2 files changed, 175 insertions(+) create mode 100644 nixos/modules/services/audio/wyoming/piper.nix diff --git a/nixos/modules/module-list.nix b/nixos/modules/module-list.nix index 83b2a45dbd3b..858252c4ba15 100644 --- a/nixos/modules/module-list.nix +++ b/nixos/modules/module-list.nix @@ -328,6 +328,7 @@ ./services/audio/spotifyd.nix ./services/audio/squeezelite.nix ./services/audio/tts.nix + ./services/audio/wyoming/piper.nix ./services/audio/ympd.nix ./services/backup/automysqlbackup.nix ./services/backup/bacula.nix diff --git a/nixos/modules/services/audio/wyoming/piper.nix b/nixos/modules/services/audio/wyoming/piper.nix new file mode 100644 index 000000000000..ed50bd9f48e9 --- /dev/null +++ b/nixos/modules/services/audio/wyoming/piper.nix @@ -0,0 +1,174 @@ +{ config +, lib +, pkgs +, ... +}: + +let + cfg = config.services.wyoming.piper; + + inherit (lib) + escapeShellArgs + mkOption + mdDoc + mkEnableOption + mkPackageOptionMD + types + ; + + inherit (builtins) + toString + ; + +in + +{ + meta.buildDocsInSandbox = false; + + options.services.wyoming.piper = with types; { + package = mkPackageOptionMD pkgs "wyoming-piper" { }; + + servers = mkOption { + default = {}; + description = mdDoc '' + Attribute set of piper instances to spawn. + ''; + type = types.attrsOf (types.submodule ( + { ... }: { + options = { + enable = mkEnableOption (mdDoc "Wyoming Piper server"); + + piper = mkPackageOptionMD pkgs "piper-tts" { }; + + voice = mkOption { + type = str; + example = "en-us-ryan-medium"; + description = mdDoc '' + Name of the voice model to use. See the following website for samples: + https://rhasspy.github.io/piper-samples/ + ''; + }; + + uri = mkOption { + type = strMatching "^(tcp|unix)://.*$"; + example = "tcp://0.0.0.0:10200"; + description = mdDoc '' + URI to bind the wyoming server to. + ''; + }; + + speaker = mkOption { + type = ints.unsigned; + default = 0; + description = mdDoc '' + ID of a specific speaker in a multi-speaker model. + ''; + apply = toString; + }; + + noiseScale = mkOption { + type = float; + default = 0.667; + description = mdDoc '' + Generator noise value. + ''; + apply = toString; + }; + + noiseWidth = mkOption { + type = float; + default = 0.333; + description = mdDoc '' + Phoneme width noise value. + ''; + apply = toString; + }; + + lengthScale = mkOption { + type = float; + default = 1.0; + description = mdDoc '' + Phoneme length value. + ''; + apply = toString; + }; + + extraArgs = mkOption { + type = listOf str; + default = [ ]; + description = mdDoc '' + Extra arguments to pass to the server commandline. + ''; + apply = escapeShellArgs; + }; + }; + } + )); + }; + }; + + config = let + inherit (lib) + mapAttrs' + mkIf + nameValuePair + ; + in mkIf (cfg.servers != {}) { + systemd.services = mapAttrs' (server: options: + nameValuePair "wyoming-piper-${server}" { + description = "Wyoming Piper server instance ${server}"; + after = [ + "network-online.target" + ]; + wantedBy = [ + "multi-user.target" + ]; + serviceConfig = { + DynamicUser = true; + User = "wyoming-piper"; + StateDirectory = "wyoming/piper"; + # https://github.com/home-assistant/addons/blob/master/piper/rootfs/etc/s6-overlay/s6-rc.d/piper/run + ExecStart = '' + ${cfg.package}/bin/wyoming-piper \ + --data-dir $STATE_DIRECTORY \ + --download-dir $STATE_DIRECTORY \ + --uri ${options.uri} \ + --piper ${options.piper}/bin/piper \ + --voice ${options.voice} \ + --speaker ${options.speaker} \ + --length-scale ${options.lengthScale} \ + --noise-scale ${options.noiseScale} \ + --noise-w ${options.noiseWidth} ${options.extraArgs} + ''; + CapabilityBoundingSet = ""; + DeviceAllow = ""; + DevicePolicy = "closed"; + LockPersonality = true; + MemoryDenyWriteExecute = true; + PrivateDevices = true; + PrivateUsers = true; + ProtectHome = true; + ProtectHostname = true; + ProtectKernelLogs = true; + ProtectKernelModules = true; + ProtectKernelTunables = true; + ProtectControlGroups = true; + ProtectProc = "invisible"; + ProcSubset = "pid"; + RestrictAddressFamilies = [ + "AF_INET" + "AF_INET6" + "AF_UNIX" + ]; + RestrictNamespaces = true; + RestrictRealtime = true; + SystemCallArchitectures = "native"; + SystemCallFilter = [ + "@system-service" + "~@privileged" + ]; + UMask = "0077"; + }; + }) cfg.servers; + }; +} From f213f33f156575661264dee8dbf81ab7c419751d Mon Sep 17 00:00:00 2001 From: Martin Weinelt Date: Fri, 9 Jun 2023 23:58:33 +0200 Subject: [PATCH 8/8] nixos/wyoming/faster-whisper: init --- nixos/modules/module-list.nix | 1 + .../services/audio/wyoming/faster-whisper.nix | 186 ++++++++++++++++++ 2 files changed, 187 insertions(+) create mode 100644 nixos/modules/services/audio/wyoming/faster-whisper.nix diff --git a/nixos/modules/module-list.nix b/nixos/modules/module-list.nix index 858252c4ba15..7377f2e937de 100644 --- a/nixos/modules/module-list.nix +++ b/nixos/modules/module-list.nix @@ -328,6 +328,7 @@ ./services/audio/spotifyd.nix ./services/audio/squeezelite.nix ./services/audio/tts.nix + ./services/audio/wyoming/faster-whisper.nix ./services/audio/wyoming/piper.nix ./services/audio/ympd.nix ./services/backup/automysqlbackup.nix diff --git a/nixos/modules/services/audio/wyoming/faster-whisper.nix b/nixos/modules/services/audio/wyoming/faster-whisper.nix new file mode 100644 index 000000000000..6317709b2475 --- /dev/null +++ b/nixos/modules/services/audio/wyoming/faster-whisper.nix @@ -0,0 +1,186 @@ +{ config +, lib +, pkgs +, ... +}: + +let + cfg = config.services.wyoming.faster-whisper; + + inherit (lib) + escapeShellArgs + mkOption + mdDoc + mkEnableOption + mkPackageOptionMD + types + ; + + inherit (builtins) + toString + ; + +in + +{ + options.services.wyoming.faster-whisper = with types; { + package = mkPackageOptionMD pkgs "wyoming-faster-whisper" { }; + + servers = mkOption { + default = {}; + description = mdDoc '' + Attribute set of faster-whisper instances to spawn. + ''; + type = types.attrsOf (types.submodule ( + { ... }: { + options = { + enable = mkEnableOption (mdDoc "Wyoming faster-whisper server"); + + model = mkOption { + type = enum [ + "tiny" + "tiny-int8" + "base" + "base-int8" + "small" + "small-int8" + "medium" + "medium-int8" + ]; + default = "tiny-int8"; + example = "medium-int8"; + description = mdDoc '' + Name of the voice model to use. + ''; + }; + + uri = mkOption { + type = strMatching "^(tcp|unix)://.*$"; + example = "tcp://0.0.0.0:10300"; + description = mdDoc '' + URI to bind the wyoming server to. + ''; + }; + + device = mkOption { + # https://opennmt.net/CTranslate2/python/ctranslate2.models.Whisper.html# + type = types.enum [ + "cpu" + "cuda" + "auto" + ]; + default = "cpu"; + description = mdDoc '' + Id of a speaker in a multi-speaker model. + ''; + }; + + language = mkOption { + type = enum [ + # https://github.com/home-assistant/addons/blob/master/whisper/config.yaml#L20 + "auto" "af" "am" "ar" "as" "az" "ba" "be" "bg" "bn" "bo" "br" "bs" "ca" "cs" "cy" "da" "de" "el" "en" "es" "et" "eu" "fa" "fi" "fo" "fr" "gl" "gu" "ha" "haw" "he" "hi" "hr" "ht" "hu" "hy" "id" "is" "it" "ja" "jw" "ka" "kk" "km" "kn" "ko" "la" "lb" "ln" "lo" "lt" "lv" "mg" "mi" "mk" "ml" "mn" "mr" "ms" "mt" "my" "ne" "nl" "nn" "no" "oc" "pa" "pl" "ps" "pt" "ro" "ru" "sa" "sd" "si" "sk" "sl" "sn" "so" "sq" "sr" "su" "sv" "sw" "ta" "te" "tg" "th" "tk" "tl" "tr" "tt" "uk" "ur" "uz" "vi" "yi" "yo" "zh" + ]; + example = "en"; + description = mdDoc '' + The language used to to parse words and sentences. + ''; + }; + + beamSize = mkOption { + type = ints.unsigned; + default = 1; + example = 5; + description = mdDoc '' + The number of beams to use in beam search. + ''; + apply = toString; + }; + + extraArgs = mkOption { + type = listOf str; + default = [ ]; + description = mdDoc '' + Extra arguments to pass to the server commandline. + ''; + apply = escapeShellArgs; + }; + }; + } + )); + }; + }; + + config = let + inherit (lib) + mapAttrs' + mkIf + nameValuePair + ; + in mkIf (cfg.servers != {}) { + systemd.services = mapAttrs' (server: options: + nameValuePair "wyoming-faster-whisper-${server}" { + description = "Wyoming faster-whisper server instance ${server}"; + after = [ + "network-online.target" + ]; + wantedBy = [ + "multi-user.target" + ]; + serviceConfig = { + DynamicUser = true; + User = "wyoming-faster-whisper"; + StateDirectory = "wyoming/faster-whisper"; + # https://github.com/home-assistant/addons/blob/master/whisper/rootfs/etc/s6-overlay/s6-rc.d/whisper/run + ExecStart = '' + ${cfg.package}/bin/wyoming-faster-whisper \ + --data-dir $STATE_DIRECTORY \ + --download-dir $STATE_DIRECTORY \ + --uri ${options.uri} \ + --model ${options.model} \ + --language ${options.language} \ + --beam-size ${options.beamSize} ${options.extraArgs} + ''; + CapabilityBoundingSet = ""; + DeviceAllow = if builtins.elem options.device [ "cuda" "auto" ] then [ + # https://docs.nvidia.com/dgx/pdf/dgx-os-5-user-guide.pdf + "/dev/nvidia1" + "/dev/nvidia2" + "/dev/nvidia3" + "/dev/nvidia4" + "/dev/nvidia-caps/nvidia-cap1" + "/dev/nvidia-caps/nvidia-cap2" + "/dev/nvidiactl" + "/dev/nvidia-modeset" + "/dev/nvidia-uvm" + "/dev/nvidia-uvm-tools" + ] else ""; + DevicePolicy = "closed"; + LockPersonality = true; + MemoryDenyWriteExecute = true; + PrivateDevices = true; + PrivateUsers = true; + ProtectHome = true; + ProtectHostname = true; + ProtectKernelLogs = true; + ProtectKernelModules = true; + ProtectKernelTunables = true; + ProtectControlGroups = true; + ProtectProc = "invisible"; + ProcSubset = "pid"; + RestrictAddressFamilies = [ + "AF_INET" + "AF_INET6" + "AF_UNIX" + ]; + RestrictNamespaces = true; + RestrictRealtime = true; + SystemCallArchitectures = "native"; + SystemCallFilter = [ + "@system-service" + "~@privileged" + ]; + UMask = "0077"; + }; + }) cfg.servers; + }; +}