diff --git a/pkgs/development/libraries/piper-phonemize/default.nix b/pkgs/development/libraries/piper-phonemize/default.nix new file mode 100644 index 000000000000..fd1c1ae34b4c --- /dev/null +++ b/pkgs/development/libraries/piper-phonemize/default.nix @@ -0,0 +1,60 @@ +{ 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="; + }; + + nativeBuildInputs = [ + cmake + pkg-config + ]; + + buildInputs = [ + espeak-ng' + onnxruntime + ]; + + passthru = { + espeak-ng = espeak-ng'; + }; + + 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/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/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 = '' 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 5cf8cdea10df..a385ebb85ad6 100644 --- a/pkgs/development/python-modules/piper-train/default.nix +++ b/pkgs/tools/audio/piper/train.nix @@ -1,38 +1,26 @@ -{ buildPythonPackage -, piper-tts - -# build -, cython -, python - -# propagates -, espeak-phonemizer -, librosa -, numpy -, onnxruntime -, 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 ''; @@ -43,11 +31,12 @@ 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 onnxruntime + piper-phonemize pytorch-lightning torch ]; @@ -57,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 798adc1832b0..bc20f46ac2c8 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -11716,7 +11716,8 @@ with pkgs; pim6sd = callPackage ../servers/pim6sd { }; - piper-train = with python3Packages; toPythonApplication piper-train; + piper-phonemize = callPackage ../development/libraries/piper-phonemize { }; + 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 83b45cde21b3..bf738d556a9f 100644 --- a/pkgs/top-level/python-packages.nix +++ b/pkgs/top-level/python-packages.nix @@ -7965,7 +7965,10 @@ self: super: with self; { pipenv-poetry-migrate = callPackage ../development/python-modules/pipenv-poetry-migrate { }; - piper-train = callPackage ../development/python-modules/piper-train { }; + piper-phonemize = callPackage ../development/python-modules/piper-phonemize { + onnxruntime-native = pkgs.onnxruntime; + piper-phonemize-native = pkgs.piper-phonemize; + }; pip-api = callPackage ../development/python-modules/pip-api { };