From 14329c27de642c4d1ccbef2eb710c2824398ad75 Mon Sep 17 00:00:00 2001 From: Martin Weinelt Date: Fri, 30 Jun 2023 01:37:40 +0200 Subject: [PATCH 1/4] piper-phonemize: init at 1.1.0 C++ library for converting text to phonemes for Piper --- .../libraries/piper-phonemize/default.nix | 73 +++++++++++++++++++ .../piper-phonemize/espeak-mbrola.patch | 26 +++++++ pkgs/top-level/all-packages.nix | 1 + 3 files changed, 100 insertions(+) create mode 100644 pkgs/development/libraries/piper-phonemize/default.nix create mode 100644 pkgs/development/libraries/piper-phonemize/espeak-mbrola.patch diff --git a/pkgs/development/libraries/piper-phonemize/default.nix b/pkgs/development/libraries/piper-phonemize/default.nix new file mode 100644 index 000000000000..137625355ec3 --- /dev/null +++ b/pkgs/development/libraries/piper-phonemize/default.nix @@ -0,0 +1,73 @@ +{ lib +, stdenv +, fetchFromGitHub + +# build +, cmake +, pkg-config + +# runtime +, espeak-ng +, onnxruntime +}: + +let + espeak-ng' = espeak-ng.overrideAttrs (oldAttrs: { + version = "1.52-dev"; + src = fetchFromGitHub { + owner = "rhasspy"; + repo = "espeak-ng"; + rev = "61504f6b76bf9ebbb39b07d21cff2a02b87c99ff"; + hash = "sha256-RBHL11L5uazAFsPFwul2QIyJREXk9Uz8HTZx9JqmyIQ="; + }; + + patches = [ + ./espeak-mbrola.patch + ]; + }); +in +stdenv.mkDerivation rec { + pname = "piper-phonemize"; + version = "1.1.0"; + + src = fetchFromGitHub { + owner = "rhasspy"; + repo = "piper-phonemize"; + rev = "refs/tags/v${version}"; + hash = "sha256-cMer7CSLOXv3jc9huVA3Oy5cjXjOX9XuEXpIWau1BNQ="; + }; + + outputs = [ + "out" + "dev" + ]; + + nativeBuildInputs = [ + cmake + pkg-config + ]; + + buildInputs = [ + espeak-ng' + onnxruntime + ]; + + ainstallPhase = '' + runHook preInstall + + install -d $out/lib + install ./libpiper_phonemize.so $out/lib + + install -d $dev/include/piper_phonemize + install -D ../src/*.hpp $dev/include + + runHook postInstall + ''; + + meta = with lib; { + description = "C++ library for converting text to phonemes for Piper"; + homepage = "https://github.com/rhasspy/piper-phonemize"; + license = licenses.mit; + maintainers = with maintainers; [ hexa ]; + }; +} diff --git a/pkgs/development/libraries/piper-phonemize/espeak-mbrola.patch b/pkgs/development/libraries/piper-phonemize/espeak-mbrola.patch new file mode 100644 index 000000000000..9d3f0aeb4abe --- /dev/null +++ b/pkgs/development/libraries/piper-phonemize/espeak-mbrola.patch @@ -0,0 +1,26 @@ +diff --git a/src/libespeak-ng/mbrowrap.c b/src/libespeak-ng/mbrowrap.c +index ae137873..9015cc01 100644 +--- a/src/libespeak-ng/mbrowrap.c ++++ b/src/libespeak-ng/mbrowrap.c +@@ -206,7 +206,7 @@ static int start_mbrola(const char *voice_path) + signal(SIGTERM, SIG_IGN); + + snprintf(charbuf, sizeof(charbuf), "%g", mbr_volume); +- execlp("mbrola", "mbrola", "-e", "-v", charbuf, ++ execlp("@mbrola/bin/mbrola", "mbrola", "-e", "-v", charbuf, + voice_path, "-", "-.wav", (char *)NULL); + /* if execution reaches this point then the exec() failed */ + snprintf(mbr_errorbuf, sizeof(mbr_errorbuf), +diff --git a/src/libespeak-ng/synth_mbrola.c b/src/libespeak-ng/synth_mbrola.c +index 734631b7..46d1f13e 100644 +--- a/src/libespeak-ng/synth_mbrola.c ++++ b/src/libespeak-ng/synth_mbrola.c +@@ -85,7 +85,7 @@ espeak_ng_STATUS LoadMbrolaTable(const char *mbrola_voice, const char *phtrans, + if (!load_MBR()) + return ENS_MBROLA_NOT_FOUND; + +- sprintf(path, "%s/mbrola/%s", path_home, mbrola_voice); ++ sprintf(path, "@mbrola@/share/mbrola/voices/%s/%s", mbrola_voice, mbrola_voice); + #if PLATFORM_POSIX + // if not found, then also look in + // usr/share/mbrola/xx, /usr/share/mbrola/xx/xx, /usr/share/mbrola/voices/xx diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index 0109d702efac..c7201ca7d59a 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -11708,6 +11708,7 @@ with pkgs; pim6sd = callPackage ../servers/pim6sd { }; + piper-phonemize = callPackage ../development/libraries/piper-phonemize { }; piper-train = with python3Packages; toPythonApplication piper-train; piper-tts = callPackage ../tools/audio/piper { }; From faa7d81bd1fab71100667515e21df684ec3f12c5 Mon Sep 17 00:00:00 2001 From: Martin Weinelt Date: Fri, 30 Jun 2023 01:44:52 +0200 Subject: [PATCH 2/4] python310Packages.piper-phonemize: init Python bindings for phonemization library used by the Piper text to speech system. --- .../libraries/piper-phonemize/default.nix | 19 ++--------- .../piper-phonemize/default.nix | 34 +++++++++++++++++++ pkgs/top-level/python-packages.nix | 5 +++ 3 files changed, 42 insertions(+), 16 deletions(-) create mode 100644 pkgs/development/python-modules/piper-phonemize/default.nix diff --git a/pkgs/development/libraries/piper-phonemize/default.nix b/pkgs/development/libraries/piper-phonemize/default.nix index 137625355ec3..fd1c1ae34b4c 100644 --- a/pkgs/development/libraries/piper-phonemize/default.nix +++ b/pkgs/development/libraries/piper-phonemize/default.nix @@ -37,11 +37,6 @@ stdenv.mkDerivation rec { hash = "sha256-cMer7CSLOXv3jc9huVA3Oy5cjXjOX9XuEXpIWau1BNQ="; }; - outputs = [ - "out" - "dev" - ]; - nativeBuildInputs = [ cmake pkg-config @@ -52,17 +47,9 @@ stdenv.mkDerivation rec { onnxruntime ]; - ainstallPhase = '' - runHook preInstall - - install -d $out/lib - install ./libpiper_phonemize.so $out/lib - - install -d $dev/include/piper_phonemize - install -D ../src/*.hpp $dev/include - - runHook postInstall - ''; + passthru = { + espeak-ng = espeak-ng'; + }; meta = with lib; { description = "C++ library for converting text to phonemes for Piper"; diff --git a/pkgs/development/python-modules/piper-phonemize/default.nix b/pkgs/development/python-modules/piper-phonemize/default.nix new file mode 100644 index 000000000000..cd09567a61e3 --- /dev/null +++ b/pkgs/development/python-modules/piper-phonemize/default.nix @@ -0,0 +1,34 @@ +{ buildPythonPackage +, onnxruntime-native +, piper-phonemize-native +, pybind11 +, setuptools +}: + +buildPythonPackage { + inherit (piper-phonemize-native) pname version src; + format = "pyproject"; + + nativeBuildInputs = [ + pybind11 + setuptools + ]; + + buildInputs = [ + onnxruntime-native + piper-phonemize-native + piper-phonemize-native.espeak-ng + ]; + + pythonImportsCheck = [ + "piper_phonemize" + ]; + + # no tests + doCheck = false; + + meta = { + description = "Phonemization libary used by Piper text to speech system"; + inherit (piper-phonemize-native.meta) homepage license maintainers; + }; +} diff --git a/pkgs/top-level/python-packages.nix b/pkgs/top-level/python-packages.nix index 83b45cde21b3..e3e9a7ce7a60 100644 --- a/pkgs/top-level/python-packages.nix +++ b/pkgs/top-level/python-packages.nix @@ -7965,6 +7965,11 @@ self: super: with self; { pipenv-poetry-migrate = callPackage ../development/python-modules/pipenv-poetry-migrate { }; + piper-phonemize = callPackage ../development/python-modules/piper-phonemize { + onnxruntime-native = pkgs.onnxruntime; + piper-phonemize-native = pkgs.piper-phonemize; + }; + piper-train = callPackage ../development/python-modules/piper-train { }; pip-api = callPackage ../development/python-modules/pip-api { }; From 1fd038e11b125b86dec15dcff8446422f3619241 Mon Sep 17 00:00:00 2001 From: Martin Weinelt Date: Fri, 30 Jun 2023 00:48:56 +0200 Subject: [PATCH 3/4] piper-tts: 0.0.2 -> 1.2.0 https://github.com/rhasspy/piper/releases/tag/v1.0.0 https://github.com/rhasspy/piper/releases/tag/v1.1.0 https://github.com/rhasspy/piper/releases/tag/v1.2.0 --- .../python-modules/piper-train/default.nix | 2 ++ pkgs/tools/audio/piper/default.nix | 32 +++++++++++-------- 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/pkgs/development/python-modules/piper-train/default.nix b/pkgs/development/python-modules/piper-train/default.nix index 5cf8cdea10df..3adb94c8f229 100644 --- a/pkgs/development/python-modules/piper-train/default.nix +++ b/pkgs/development/python-modules/piper-train/default.nix @@ -10,6 +10,7 @@ , librosa , numpy , onnxruntime +, piper-phonemize , pytorch-lightning , torch }: @@ -48,6 +49,7 @@ buildPythonPackage { librosa numpy onnxruntime + piper-phonemize pytorch-lightning torch ]; diff --git a/pkgs/tools/audio/piper/default.nix b/pkgs/tools/audio/piper/default.nix index c3d8a7638304..29fdb0705fec 100644 --- a/pkgs/tools/audio/piper/default.nix +++ b/pkgs/tools/audio/piper/default.nix @@ -1,17 +1,24 @@ { lib , stdenv , fetchFromGitHub + +# build time , cmake , pkg-config -, espeak-ng + +# runtime , onnxruntime , pcaudiolib +, piper-phonemize +, spdlog + +# tests , piper-train }: let pname = "piper"; - version = "0.0.2"; + version = "1.2.0"; in stdenv.mkDerivation { inherit pname version; @@ -19,30 +26,27 @@ stdenv.mkDerivation { src = fetchFromGitHub { owner = "rhasspy"; repo = "piper"; - rev = "70afec58bc131010c8993c154ff02a78d1e7b8b0"; - hash = "sha256-zTW7RGcV8Hh7G6Braf27F/8s7nNjAqagp7tmrKO10BY="; + rev = "refs/tags/v${version}"; + hash = "sha256-6WNWqJt0PO86vnf+3iHaRRg2KwBOEj4aicmB+P2phlk="; }; sourceRoot = "source/src/cpp"; - patches = [ - ./fix-compilation-with-newer-onnxruntime.patch - ]; - - postPatch = '' - substituteInPlace CMakeLists.txt \ - --replace "/usr/local/include/onnxruntime" "${onnxruntime}" - ''; - nativeBuildInputs = [ cmake pkg-config ]; buildInputs = [ - espeak-ng onnxruntime pcaudiolib + piper-phonemize + piper-phonemize.espeak-ng + spdlog + ]; + + env.NIX_CFLAGS_COMPILE = builtins.toString [ + "-isystem ${lib.getDev piper-phonemize}/include/piper-phonemize" ]; installPhase = '' From 24c0ba0ffcce19a168a61bac47c96d7d7e9e930e Mon Sep 17 00:00:00 2001 From: Martin Weinelt Date: Thu, 3 Aug 2023 03:03:21 +0200 Subject: [PATCH 4/4] piper-train: move to top-level and mark broken Requires torch<2, which is difficult to provide in an override, so I'd rather wait until they catch up. --- .../audio/piper/train.nix} | 44 ++++++++----------- pkgs/top-level/all-packages.nix | 2 +- pkgs/top-level/python-aliases.nix | 1 - pkgs/top-level/python-packages.nix | 2 - 4 files changed, 19 insertions(+), 30 deletions(-) rename pkgs/{development/python-modules/piper-train/default.nix => tools/audio/piper/train.nix} (56%) diff --git a/pkgs/development/python-modules/piper-train/default.nix b/pkgs/tools/audio/piper/train.nix similarity index 56% rename from pkgs/development/python-modules/piper-train/default.nix rename to pkgs/tools/audio/piper/train.nix index 3adb94c8f229..a385ebb85ad6 100644 --- a/pkgs/development/python-modules/piper-train/default.nix +++ b/pkgs/tools/audio/piper/train.nix @@ -1,39 +1,26 @@ -{ buildPythonPackage -, piper-tts - -# build -, cython -, python - -# propagates -, espeak-phonemizer -, librosa -, numpy -, onnxruntime -, piper-phonemize -, pytorch-lightning -, torch +{ piper-tts +, python3 }: -buildPythonPackage { - inherit (piper-tts) version src meta; +let + python = python3.override { + packageOverrides = self: super: { + }; + }; +in + +python.pkgs.buildPythonPackage { + inherit (piper-tts) version src; pname = "piper-train"; format = "setuptools"; sourceRoot = "source/src/python"; - nativeBuildInputs = [ + nativeBuildInputs = with python.pkgs; [ cython ]; - postPatch = '' - substituteInPlace requirements.txt \ - --replace "onnxruntime~=1.11.0" "onnxruntime" \ - --replace "pytorch-lightning~=1.7.0" "pytorch-lightning" \ - --replace "torch~=1.11.0" "torch" - ''; - postBuild = '' make -C piper_train/vits/monotonic_align ''; @@ -44,7 +31,7 @@ buildPythonPackage { cp -v ./piper_train/vits/monotonic_align/piper_train/vits/monotonic_align/core.*.so $MONOTONIC_ALIGN/ ''; - propagatedBuildInputs = [ + propagatedBuildInputs = with python.pkgs; [ espeak-phonemizer librosa numpy @@ -59,4 +46,9 @@ buildPythonPackage { ]; doCheck = false; # no tests + + meta = piper-tts.meta // { + # requires torch<2, pytorch-lightning~=1.7 + broken = true; + }; } diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index c7201ca7d59a..09407ff1ca05 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -11709,7 +11709,7 @@ with pkgs; pim6sd = callPackage ../servers/pim6sd { }; piper-phonemize = callPackage ../development/libraries/piper-phonemize { }; - piper-train = with python3Packages; toPythonApplication piper-train; + piper-train = callPackage ../tools/audio/piper/train.nix { }; piper-tts = callPackage ../tools/audio/piper { }; phosh = callPackage ../applications/window-managers/phosh { }; diff --git a/pkgs/top-level/python-aliases.nix b/pkgs/top-level/python-aliases.nix index a6ef2838bcb6..63addfa58a03 100644 --- a/pkgs/top-level/python-aliases.nix +++ b/pkgs/top-level/python-aliases.nix @@ -184,7 +184,6 @@ 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 e3e9a7ce7a60..bf738d556a9f 100644 --- a/pkgs/top-level/python-packages.nix +++ b/pkgs/top-level/python-packages.nix @@ -7970,8 +7970,6 @@ self: super: with self; { piper-phonemize-native = pkgs.piper-phonemize; }; - piper-train = callPackage ../development/python-modules/piper-train { }; - pip-api = callPackage ../development/python-modules/pip-api { }; pip-tools = callPackage ../development/python-modules/pip-tools { };