summary refs log tree commit diff
path: root/pkgs/development/libraries/speechd/default.nix
blob: 43360d781cdbb8c0915634f4f201c685ad06dd10 (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
{ stdenv, pkgconfig, fetchurl, python3Packages
, intltool, itstool, libtool, texinfo, autoreconfHook
, glib, dotconf, libsndfile
, withLibao ? true, libao
, withPulse ? false, libpulseaudio
, withAlsa ? false, alsaLib
, withOss ? false
, withFlite ? true, flite
# , withFestival ? false, festival-freebsoft-utils
, withEspeak ? true, espeak, sonic, pcaudiolib
, withPico ? true, svox
# , withIvona ? false, libdumbtts
}:

let
  inherit (stdenv.lib) optional optionals;
  inherit (python3Packages) python pyxdg wrapPython;

  # speechd hard-codes espeak, even when built without support for it.
  selectedDefaultModule =
    if withEspeak then
      "espeak-ng"
    else if withPico then
      "pico"
    else if withFlite then
      "flite"
    else
      throw "You need to enable at least one output module.";
in stdenv.mkDerivation rec {
  pname = "speech-dispatcher";
  version = "0.8.8";

  src = fetchurl {
    url = "http://www.freebsoft.org/pub/projects/speechd/${pname}-${version}.tar.gz";
    sha256 = "1wvck00w9ixildaq6hlhnf6wa576y02ac96lp6932h3k1n08jaiw";
  };

  nativeBuildInputs = [ pkgconfig autoreconfHook intltool libtool itstool texinfo wrapPython ];

  buildInputs = [ glib dotconf libsndfile libao libpulseaudio alsaLib python ]
    ++ optionals withEspeak [ espeak sonic pcaudiolib ]
    ++ optional withFlite flite
    ++ optional withPico svox
    # TODO: add flint/festival support with festival-freebsoft-utils package
    # ++ optional withFestival festival-freebsoft-utils
    # TODO: add Ivona support with libdumbtts package
    # ++ optional withIvona libdumbtts
  ;

  pythonPath = [ pyxdg ];

  configureFlags = [
    # Audio method falls back from left to right.
    "--with-default-audio-method=\"libao,pulse,alsa,oss\""
  ] ++ optional withPulse "--with-pulse"
    ++ optional withAlsa "--with-alsa"
    ++ optional withLibao "--with-libao"
    ++ optional withOss "--with-oss"
    ++ optional withEspeak "--with-espeak-ng"
    ++ optional withPico "--with-pico"
    # ++ optional withFestival "--with-flint"
    # ++ optional withIvona "--with-ivona"
  ;

  postPatch = ''
    substituteInPlace config/speechd.conf --replace "DefaultModule espeak" "DefaultModule ${selectedDefaultModule}"
    substituteInPlace src/modules/pico.c --replace "/usr/share/pico/lang" "${svox}/share/pico/lang"
  '';

  postInstall = ''
    wrapPythonPrograms
  '';

  meta = with stdenv.lib; {
    description = "Common interface to speech synthesis";
    homepage = https://devel.freebsoft.org/speechd;
    license = licenses.gpl2Plus;
    maintainers = with maintainers; [ berce ];
    platforms = platforms.linux;
  };
}