Debian Codegraph @

emscripten/README.md

raw symbols SCIP
1 # espeakng.js
2
3 This port of
4 [eSpeak-ng](https://github.com/espeak-ng/espeak-ng)
5 to Javascript via
6 [emscripten](http://emscripten.org)
7 allows client-side text-to-speech synthesis in any browser
8 supporting Web workers and the Web Audio API.
9
10 * Version: 1.49.1
11 * Date: 2017-05-01
12 * License: the GNU General Public License, Version 3 (GPLv3)
13 * Size: 3.2 MB (including all the voices)
14
15
16 ## Demo
17
18 For an online demo, visit [this page](https://www.readbeyond.it/espeakng/).
19
20 If you prefer a local demo, open the file [`demo.html`](demo.html) in your browser.
21 (Depending on your browser, you might need to serve it via a Web server.
22 A simple way consists in calling `$ python -m SimpleHTTPServer 8000`
23 and pointing your browser to `http://localhost:8000/demo.html`)
24
25
26 ## Usage
27
28 1. Include `js/espeakng.js` in your HTML file:
29
30 ```html
31 <script type="text/javascript" src="js/espeakng.js"></script>
32 ```
33
34 2. Create a new `eSpeakNG` instance with the path of the worker
35 (e.g., `js/espeakng.worker.js`) as the first argument.
36 You can supply a callback function that will be called once the worker is ready:
37
38 ```js
39 <script>
40 var tts = new eSpeakNG('js/espeakng.worker.js', function(){
41 // now tts is initialized and
42 // you can call tts.function(...)
43 ...
44 });
45 </script>
46 ```
47
48 3. Functions exposed by the `eSpeakNG` object:
49
50 * `list_voices(cb(voices))`: obtain the list of available voices, passing it (`voices`) to the callback function `cb`
51 * `set_rate(value)`: set the rate of the synthesized speech, `value` must be an integer in `[80..450]`, default `175`
52 * `set_pitch(value)`: set the pitch of the synthesized speech, `value` must be an integer in `[0..99]`, default `50`
53 * `set_voice.apply(espeakng, voice)`: set the voice for synthesizing speech, `voice` must be the code string for the desired voice (e.g., `en`, `en-us`, `it`, etc.)
54 * `synthesize(text, cb(samples, events))`: synthesize the given string `text` and call the callback function `cb` when done, passing the generated audio samples (`samples`) and events (`events`)
55
56 See the file [`demo.html`](demo.html) for details.
57
58
59 ## Download
60
61 You can download pre-built JS/data files from the
62 [jsdelivr CDN](http://www.jsdelivr.com/).
63 You need to get the following files:
64
65 ```
66 # Latest version
67 https://cdn.jsdelivr.net/espeakng.js/latest/espeakng.min.js
68 https://cdn.jsdelivr.net/espeakng.js/latest/espeakng.worker.js
69 https://cdn.jsdelivr.net/espeakng.js/latest/espeakng.worker.data
70
71 # Specific version
72 https://cdn.jsdelivr.net/espeakng.js/1.49.0/espeakng.min.js
73 https://cdn.jsdelivr.net/espeakng.js/1.49.0/espeakng.worker.js
74 https://cdn.jsdelivr.net/espeakng.js/1.49.0/espeakng.worker.data
75 ```
76
77 For details, see the
78 [espeakng.js-cdn](https://github.com/pettarin/espeakng.js-cdn)
79 repository.
80
81
82 ## Building
83
84 1. Make sure you have `emscripten`
85 [installed and activated](http://kripken.github.io/emscripten-site/docs/getting_started/downloads.html),
86 and configured in your shell.
87
88 2. Clone the repository, enter the `espeak-ng` directory, and initialize it:
89
90 ```bash
91 $ git clone https://github.com/espeak-ng/espeak-ng
92 $ cd espeak-ng
93 $ ./autogen.sh
94 ```
95
96 3. Compile `espeak-ng`:
97
98 ```bash
99 $ ./configure --prefix=/usr --without-async --without-mbrola --without-sonic
100 $ make
101 ```
102
103 Instead, if you just want a subset of languages of your choice,
104 run `make XX` for each of them, where `XX` is the language code.
105 For example:
106
107 ```bash
108 $ # build English only
109 $ make en
110 $
111 $ # build English, Italian, and German
112 $ make en && make it && make de
113 ```
114
115 4. Enter the `src/ucd-tools` directory, `make clean` it, and compile with `emconfigure` and `emmake`:
116
117 ```bash
118 $ cd src/ucd-tools
119 $ ./autogen.sh
120 $ make clean
121 $ emconfigure ./configure
122 $ emmake make
123 $ cd ../..
124 ```
125
126 5. Recompile the `espeak-ng` library with `emconfigure` and `emmake`:
127
128 ```bash
129 $ emconfigure ./configure --prefix=/usr --without-async --without-mbrola --without-sonic
130 $ emmake make src/libespeak-ng.la
131 ```
132
133 6. Enter the `emscripten` directory and compile the JS worker with `emmake`:
134
135 ```bash
136 $ cd emscripten
137 $ emmake make
138 ```
139
140 7. The `js/` directory should contain the output JS files:
141
142 * `espeakng.js`,
143 * `espeakng.worker.js`, and
144 * `espeakng.worker.data`.
145
146 ### Notes
147
148 * Even if you build only a subset of languages,
149 the `list_voices()` function will still list all the available voices.
150 However, if you try using language that has not been built,
151 you will get a runtime error.
152 (TODO: fix this issue.)
153 * The `-O3` optimization flag is passed to `emscripten` by default,
154 achieving a considerable reduction of the size of the generated JS worker.
155 If you want to omit it, for example for debug purposes,
156 just export the `EM_DEBUG` environment variable with value `1`
157 (i.e., `$ export EM_DEBUG=1`) before step 3.
158 * To remove intermediate files compiled by emscripten,
159 run `$ emmake clean-intermediate`.
160 This command will keep the output JS files, if any.
161 * To remove all the files compiled by emscripten,
162 including the output JS files,
163 run `$ emmake clean`.
164
165
166 ## Credits
167
168 [Eitan Isaacson](https://blog.monotonous.org/) wrote the [original glue code](https://github.com/eeejay/espeak/tree/emscripten) for compiling eSpeak to Javascript via emscripten.
169
170 [Alberto Pettarin](http://www.albertopettarin.it) adapted Eitan's files [to work with eSpeak-ng](https://github.com/pettarin/espeak-ng/tree/emscripten) and wrote this `README` file.