1{
2 stdenv,
3 lib,
4 fetchFromGitHub,
5 fetchpatch,
6 autoconf,
7 automake,
8 which,
9 libtool,
10 pkg-config,
11 ronn,
12 replaceVars,
13 buildPackages,
14 mbrolaSupport ? true,
15 mbrola,
16 pcaudiolibSupport ? true,
17 pcaudiolib,
18 sonicSupport ? true,
19 sonic,
20 alsa-plugins,
21 makeWrapper,
22}:
23
24stdenv.mkDerivation rec {
25 pname = "espeak-ng";
26 version = "1.51.1";
27
28 src = fetchFromGitHub {
29 owner = "espeak-ng";
30 repo = "espeak-ng";
31 rev = version;
32 hash = "sha256-aAJ+k+kkOS6k835mEW7BvgAIYGhUHxf7Q4P5cKO8XTk=";
33 };
34
35 patches = [
36 # Fix build with Clang 16.
37 (fetchpatch {
38 url = "https://github.com/espeak-ng/espeak-ng/commit/497c6217d696c1190c3e8b992ff7b9110eb3bedd.patch";
39 hash = "sha256-KfzqnRyQfz6nuMKnsHoUzb9rn9h/Pg54mupW1Cr+Zx0=";
40 })
41 ]
42 ++ lib.optionals mbrolaSupport [
43 # Hardcode correct mbrola paths.
44 (replaceVars ./mbrola.patch {
45 inherit mbrola;
46 })
47 ];
48
49 nativeBuildInputs = [
50 autoconf
51 automake
52 which
53 libtool
54 pkg-config
55 ronn
56 makeWrapper
57 ];
58
59 buildInputs =
60 lib.optional mbrolaSupport mbrola
61 ++ lib.optional pcaudiolibSupport pcaudiolib
62 ++ lib.optional sonicSupport sonic;
63
64 # touch ChangeLog to avoid below error on darwin:
65 # Makefile.am: error: required file './ChangeLog.md' not found
66 preConfigure =
67 lib.optionalString stdenv.hostPlatform.isDarwin ''
68 touch ChangeLog
69 ''
70 + ''
71 ./autogen.sh
72 '';
73
74 configureFlags = [
75 "--with-mbrola=${if mbrolaSupport then "yes" else "no"}"
76 ];
77
78 # ref https://github.com/void-linux/void-packages/blob/3cf863f894b67b3c93e23ac7830ca46b697d308a/srcpkgs/espeak-ng/template#L29-L31
79 postConfigure = lib.optionalString (!stdenv.buildPlatform.canExecute stdenv.hostPlatform) ''
80 substituteInPlace Makefile \
81 --replace 'ESPEAK_DATA_PATH=$(CURDIR) src/espeak-ng' 'ESPEAK_DATA_PATH=$(CURDIR) ${lib.getExe buildPackages.espeak-ng}' \
82 --replace 'espeak-ng-data/%_dict: src/espeak-ng' 'espeak-ng-data/%_dict: ${lib.getExe buildPackages.espeak-ng}' \
83 --replace '../src/espeak-ng --compile' "${lib.getExe buildPackages.espeak-ng} --compile"
84 '';
85
86 postInstall = lib.optionalString stdenv.hostPlatform.isLinux ''
87 patchelf --set-rpath "$(patchelf --print-rpath $out/bin/espeak-ng)" $out/bin/speak-ng
88 wrapProgram $out/bin/espeak-ng \
89 --set ALSA_PLUGIN_DIR ${alsa-plugins}/lib/alsa-lib
90 '';
91
92 passthru = {
93 inherit mbrolaSupport;
94 };
95
96 meta = with lib; {
97 description = "Open source speech synthesizer that supports over 70 languages, based on eSpeak";
98 homepage = "https://github.com/espeak-ng/espeak-ng";
99 changelog = "https://github.com/espeak-ng/espeak-ng/blob/${version}/CHANGELOG.md";
100 license = licenses.gpl3Plus;
101 maintainers = with maintainers; [ aske ];
102 platforms = platforms.all;
103 mainProgram = "espeak-ng";
104 };
105}