summary refs log tree commit diff
path: root/pkgs/tools/audio/tts/default.nix
blob: bb5eda93a59bc2d143bc5b8d6824d29a302aee4b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
{ lib
, python3
, fetchFromGitHub
, fetchpatch
}:

# USAGE:
# $ tts-server --list_models
# # pick your favorite vocoder/tts model
# $ tts-server --model_name tts_models/en/ljspeech/glow-tts --vocoder_name vocoder_models/universal/libri-tts/fullband-melgan
#
# If you upgrade from an old version you may have to delete old models from ~/.local/share/tts
#
# For now, for deployment check the systemd unit in the pull request:
#   https://github.com/NixOS/nixpkgs/pull/103851#issue-521121136

python3.pkgs.buildPythonApplication rec {
  pname = "tts";
  version = "0.1.3";

  src = fetchFromGitHub {
    owner = "coqui-ai";
    repo = "TTS";
    rev = "v${version}";
    sha256 = "0akhiaaqz53bf5zyps3vgjifmgh5wvcc9r4lrq9hmj3dds03vkjq";
  };

  postPatch = ''
    sed -i -e 's!librosa==[^"]*!librosa!' requirements.txt
    sed -i -e 's!numba==[^"]*!numba!' requirements.txt
    sed -i -e 's!numpy==[^"]*!numpy!' requirements.txt
    sed -i -e 's!umap-learn==[^"]*!umap-learn!' requirements.txt
  '';

  nativeBuildInputs = with python3.pkgs; [
    cython
  ];

  propagatedBuildInputs = with python3.pkgs; [
    anyascii
    coqpit
    flask
    gruut
    gdown
    inflect
    jieba
    librosa
    matplotlib
    mecab-python3
    numba
    pandas
    pypinyin
    pysbd
    pytorch
    scipy
    soundfile
    tensorboardx
    tensorflow
    tqdm
    umap-learn
    unidic-lite
  ];

  postInstall = ''
    cp -r TTS/server/templates/ $out/${python3.sitePackages}/TTS/server
    # cython modules are not installed for some reasons
    (
      cd TTS/tts/layers/glow_tts/monotonic_align
      ${python3.interpreter} setup.py install --prefix=$out
    )
  '';

  checkInputs = with python3.pkgs; [
    pytest-sugar
    pytestCheckHook
  ];

  disabledTests = [
    # RuntimeError: fft: ATen not compiled with MKL support
    "test_torch_stft"
    "test_stft_loss"
    "test_multiscale_stft_loss"
    # Requires network acccess to download models
    "test_synthesize"
  ];

  preCheck = ''
    # use the installed TTS in $PYTHONPATH instead of the one from source to also have cython modules.
    mv TTS{,.old}
    export PATH=$out/bin:$PATH

    # numba tries to write to HOME directory
    export HOME=$TMPDIR

    for file in $(grep -rl 'python TTS/bin' tests); do
      substituteInPlace "$file" \
        --replace "python TTS/bin" "${python3.interpreter} $out/lib/${python3.libPrefix}/site-packages/TTS/bin"
    done
  '';

  disabledTestPaths = [
    # requires tensorflow
    "tests/vocoder_tests/test_vocoder_tf_pqmf.py"
    "tests/vocoder_tests/test_vocoder_tf_melgan_generator.py"
    "tests/tts_tests/test_tacotron2_tf_model.py"
    # RuntimeError: fft: ATen not compiled with MKL support
    "tests/vocoder_tests/test_fullband_melgan_train.py"
    "tests/vocoder_tests/test_hifigan_train.py"
    "tests/vocoder_tests/test_melgan_train.py"
    "tests/vocoder_tests/test_multiband_melgan_train.py"
    "tests/vocoder_tests/test_parallel_wavegan_train.py"
  ];

  meta = with lib; {
    homepage = "https://github.com/coqui-ai/TTS";
    changelog = "https://github.com/coqui-ai/TTS/releases/tag/v${version}";
    description = "Deep learning toolkit for Text-to-Speech, battle-tested in research and production";
    license = licenses.mpl20;
    maintainers = with maintainers; [ hexa mic92 ];
  };
}