Unverified Commit f5a3fe1a authored by Samuel Ainsworth's avatar Samuel Ainsworth Committed by GitHub
Browse files

python3Packages.{kokoro, misaki}: init at 0-unstable-2025-06-16 (#417378)

parents 5ff356ea 1bd1a4c5
Loading
Loading
Loading
Loading
+59 −0
Original line number Diff line number Diff line
{
  buildPythonPackage,
  fetchFromGitHub,
  fetchPypi,
  hatchling,
  huggingface-hub,
  lib,
  loguru,
  misaki,
  numpy,
  pytestCheckHook,
  torch,
  transformers,
}:

buildPythonPackage {
  pname = "kokoro";
  version = "0-unstable-2025-06-16";
  pyproject = true;

  src = fetchFromGitHub {
    owner = "hexgrad";
    repo = "kokoro";
    rev = "2668b2e279d0f94977995230e523b0183763f30e";
    hash = "sha256-slXbn0W1632Hak6Z0ofF0gyavxRLoxS4fyPQLHSapjA=";
  };

  build-system = [
    hatchling
  ];

  dependencies = [
    huggingface-hub
    loguru
    misaki
    numpy
    torch
    transformers
  ] ++ misaki.optional-dependencies.en; # kokoro depends on misaki[en]

  nativeCheckInputs = [ pytestCheckHook ];

  disabledTests = [
    # See https://github.com/hexgrad/kokoro/issues/225
    "test_different_window_sizes"
    "test_stft_reconstruction"
  ];

  pythonImportsCheck = [
    "kokoro"
  ];

  meta = {
    description = "Open-weight TTS model with 82 million parameters";
    homepage = "https://github.com/hexgrad/kokoro";
    license = lib.licenses.asl20;
    maintainers = with lib.maintainers; [ samuela ];
  };
}
+118 −0
Original line number Diff line number Diff line
{
  addict,
  buildPythonPackage,
  espeak-ng,
  fetchFromGitHub,
  fetchpatch2,
  fugashi,
  hatchling,
  jaconv,
  jamo,
  jieba,
  lib,
  nltk,
  num2words,
  ordered-set,
  phonemizer,
  pip,
  pypinyin,
  pythonOlder,
  regex,
  replaceVars,
  spacy-curated-transformers,
  spacy,
  pytestCheckHook,
  stdenv,
  torch,
  transformers,
  unidic,
}:

buildPythonPackage {
  pname = "misaki";
  version = "0-unstable-2025-06-16";
  pyproject = true;

  src = fetchFromGitHub {
    owner = "hexgrad";
    repo = "misaki";
    rev = "49ddead831fc1a46beab3f9cb6064d93fd3f6347";
    hash = "sha256-XkmCG0Vkw/iyLNmwhaW5gp6sg8ieHFeK6fBJ3Jb+J8Q=";
  };

  patches = [
    (fetchpatch2 {
      name = "pr82-remove-pip-dependency.patch";
      url = "https://github.com/hexgrad/misaki/commit/7d2fdff9fe046dd52b638bbb1b243fb789f4cb31.patch?full_index=1";
      hash = "sha256-N796YWrGe51FYVdxbQ8omJxeGdvOAiKEUKhhm10TQO8=";
    })
    (replaceVars ./set-espeak-paths.patch {
      espeak-library-path = "${lib.getLib espeak-ng}/lib/libespeak-ng${stdenv.hostPlatform.extensions.sharedLibrary}";
      espeak-data-path = "${lib.getLib espeak-ng}/share/espeak-ng-data";
    })
  ];

  build-system = [
    hatchling
  ];

  dependencies = [
    addict
    regex
  ];

  # See https://github.com/hexgrad/misaki/blob/main/pyproject.toml#L26
  passthru.optional-dependencies = {
    en = [
      num2words
      spacy
      spacy-curated-transformers
      phonemizer
      # phonemizer-fork -- we already patch phonemizer in nixpkgs, no need for the "-fork" version
      # espeakng-loader -- ./set-espeak-paths.patch obviates the need for this
      torch
      transformers
    ];
    ja = [
      fugashi
      jaconv
      # mojimoji -- not packaged as of 2025-06-16
      unidic
      # pyopenjtalk -- not packaged as of 2025-06-16
    ];
    ko = [
      jamo
      nltk
    ];
    zh = [
      jieba
      ordered-set
      pypinyin
      # cn2an -- not packaged as of 2025-06-16
      # pypinyin-dict -- not packaged as of 2025-06-16
    ];
    vi = [
      num2words
      spacy
      spacy-curated-transformers
      # underthesea -- not packaged as of 2025-06-16
    ];
    # he = [ mishkal-hebrew ]; -- not packaged as of 2025-06-16
  };

  # Package does not have tests as of 2025-06-16, but phonemizer is required for
  # pythonImportsCheck.
  nativeCheckInputs = [ phonemizer ];

  pythonImportsCheck = [
    "misaki"
    "misaki.espeak"
  ];

  meta = {
    description = "G2P engine for TTS";
    homepage = "https://github.com/hexgrad/misaki";
    license = lib.licenses.asl20;
    maintainers = with lib.maintainers; [ samuela ];
  };
}
+20 −0
Original line number Diff line number Diff line
diff --git a/misaki/espeak.py b/misaki/espeak.py
index e5d880c..42c2596 100644
--- a/misaki/espeak.py
+++ b/misaki/espeak.py
@@ -1,13 +1,12 @@
 from phonemizer.backend.espeak.wrapper import EspeakWrapper
 from typing import Tuple
-import espeakng_loader
 import phonemizer
 import re
 
 # Set espeak-ng library path and espeak-ng-data
-EspeakWrapper.set_library(espeakng_loader.get_library_path())
+EspeakWrapper.set_library("@espeak-library-path@")
 # Change data_path as needed when editing espeak-ng phonemes
-EspeakWrapper.set_data_path(espeakng_loader.get_data_path())
+EspeakWrapper.set_data_path("@espeak-data-path@")
 
 # EspeakFallback is used as a last resort for English
 class EspeakFallback:
+8 −0
Original line number Diff line number Diff line
@@ -4,6 +4,7 @@
  replaceVars,
  buildPythonPackage,
  fetchPypi,
  fetchpatch2,
  joblib,
  segments,
  attrs,
@@ -31,6 +32,13 @@ buildPythonPackage rec {
      libespeak = "${lib.getLib espeak-ng}/lib/libespeak-ng${stdenv.hostPlatform.extensions.sharedLibrary}";
      # FIXME package festival
    })
    # This patch is needed for python3Packages.misaki. See https://github.com/thewh1teagle/espeakng-loader?tab=readme-ov-file#usage-with-phonemizer
    # and https://github.com/bootphon/phonemizer/pull/191.
    (fetchpatch2 {
      name = "pr191-add-option-to-use-custom-espeak-data-path.patch";
      url = "https://github.com/bootphon/phonemizer/commit/cc1db4bfaf688fdfb8275fd83d218f06411455e6.patch?full_index=1";
      hash = "sha256-PMeX7A9BBVLS3Sk/Lum85GpJzKXM5tULTWSURq3MD8E=";
    })
  ];

  propagatedBuildInputs = [
+4 −0
Original line number Diff line number Diff line
@@ -7655,6 +7655,8 @@ self: super: with self; {
  knx-frontend = callPackage ../development/python-modules/knx-frontend { };
  kokoro = callPackage ../development/python-modules/kokoro { };
  kombu = callPackage ../development/python-modules/kombu { };
  konnected = callPackage ../development/python-modules/konnected { };
@@ -9107,6 +9109,8 @@ self: super: with self; {
  misaka = callPackage ../development/python-modules/misaka { };
  misaki = callPackage ../development/python-modules/misaki { };
  misoc = callPackage ../development/python-modules/misoc { };
  miss-hit = callPackage ../development/python-modules/miss-hit { };