forked from macdonst/SpeechSynthesisPlugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSpeechSynthesis.js
58 lines (49 loc) · 1.84 KB
/
SpeechSynthesis.js
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
var exec = require("cordova/exec");
var SpeechSynthesisVoiceList = require("org.apache.cordova.speech.speechsynthesis.SpeechSynthesisVoiceList");
var SpeechSynthesis = function() {
this.pending = false;
this.speaking = false;
this.paused = false;
this._voices = null;
var that = this;
var successCallback = function(data) {
that._voices = new SpeechSynthesisVoiceList(data);
};
exec(successCallback, null, "SpeechSynthesis", "startup", []);
};
SpeechSynthesis.prototype.speak = function(utterance) {
var successCallback = function(event) {
if (event.type === "start" && typeof utterance.onstart === "function") {
utterance.onstart(event);
} else if (event.type === "end" && typeof utterance.onend === "function") {
utterance.onend(event);
} else if (event.type === "pause" && typeof utterance.onpause === "function") {
utterance.onpause(event);
} else if (event.type === "resume" && typeof utterance.onresume === "function") {
utterance.onresume(event);
} else if (event.type === "mark" && typeof utterance.onmark === "function") {
utterance.onmark(event);
} else if (event.type === "boundry" && typeof utterance.onboundry === "function") {
utterance.onboundry(event);
}
};
var errorCallback = function() {
if (typeof utterance.onerror === "function") {
utterance.onerror();
}
};
exec(successCallback, errorCallback, "SpeechSynthesis", "speak", [utterance]);
};
SpeechSynthesis.prototype.cancel = function() {
exec(null, null, "SpeechSynthesis", "cancel", []);
};
SpeechSynthesis.prototype.pause = function() {
exec(null, null, "SpeechSynthesis", "pause", []);
};
SpeechSynthesis.prototype.resume = function() {
exec(null, null, "SpeechSynthesis", "resume", []);
};
SpeechSynthesis.prototype.getVoices = function() {
return this._voices;
};
module.exports = new SpeechSynthesis();