-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathspeech.mjs
More file actions
44 lines (43 loc) · 901 Bytes
/
speech.mjs
File metadata and controls
44 lines (43 loc) · 901 Bytes
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
const speechtable = {
":": "コロン",
";": "セミコロン",
"'": "クォート",
"\"": "ダブルクォート",
",": "コンマ",
".": "ドット",
"-": "マイナス",
"?": "はてな",
"#": "ハッシュ",
"!": "エクスクラメーション",
"^": "ハット",
")": "みぎかっこ",
"}": "みぎちゅうかっこ",
">": "だいなり",
"RUN": "ラン",
};
const speech = (s) => {
if (!window.SpeechSynthesisUtterance) {
//console.log("not supported speech API");
return;
}
if (typeof s == "number") {
s = String.fromCharCode(s);
const ss = speechtable[s];
if (ss) {
s = ss;
}
}
const msg = new SpeechSynthesisUtterance();
msg.volume = 1.0;
msg.rate = 2.0;
msg.pitch = 1.0;
// msg.lang = sellang.value; // en-US or ja-JP
msg.text = s;
speechSynthesis.speak(msg);
/*
msg.onend = (e) => {
console.log(e.elapsedTime);
};
*/
};
export { speech };