Debian Codegraph @

emscripten/js/espeakng.js

raw symbols SCIP
1 /*
2 * Copyright (C) 2014-2017 Eitan Isaacson
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, see: <http://www.gnu.org/licenses/>.
16 */
17
18 function eSpeakNG(worker_path, ready_cb) {
19 this.worker = new Worker(worker_path);
20 this.ready = false;
21 this.worker.onmessage = function(e) {
22 if (e.data !== 'ready') {
23 return;
24 }
25 this.worker.onmessage = null;
26 this.worker.addEventListener('message', this);
27 this.ready = true;
28 if (ready_cb) {
29 ready_cb();
30 }
31 }.bind(this);
32 }
33
34 eSpeakNG.prototype.handleEvent = function (evt) {
35 var callback = evt.data.callback;
36 if (callback && this[callback]) {
37 this[callback].apply(this, evt.data.result);
38 if (evt.data.done) {
39 delete this[callback];
40 }
41 return;
42 }
43 };
44
45 function _createAsyncMethod(method) {
46 return function() {
47 var lastArg = arguments[arguments.length - 1];
48 var message = { method: method, args: Array.prototype.slice.call(arguments, 0) };
49 if (typeof lastArg == 'function') {
50 var callback = '_' + method + '_' + Math.random().toString().substring(2) +'_cb';
51 this[callback] = lastArg;
52 message.args.pop();
53 message.callback = callback;
54 }
55 this.worker.postMessage(message);
56 };
57 }
58
59 for (var method of [
60 'list_voices',
61 'get_rate',
62 'get_pitch',
63 'set_rate',
64 'set_pitch',
65 'set_voice',
66 'synthesize',
67 'synthesize_ipa'
68 ]) {
69 eSpeakNG.prototype[method] = _createAsyncMethod(method);
70 }