added tts to extensions

snap7
jmoenig 2021-06-15 11:51:08 +02:00
rodzic 95efc1a93c
commit 66a0d6803f
2 zmienionych plików z 19 dodań i 2 usunięć

Wyświetl plik

@ -11,6 +11,7 @@
* updated frequency-distribution-analysis library
* updated animation library
* updated words-sentences library
' extensions: added tts
### 2021-06-14
* new dev version

Wyświetl plik

@ -27,7 +27,7 @@
// Global settings /////////////////////////////////////////////////////
/*global modules, List, StageMorph, Costume*/
/*global modules, List, StageMorph, Costume, SpeechSynthesisUtterance*/
modules.extensions = '2021-June-15';
@ -46,7 +46,7 @@ var SnapExtensions = new Map();
example: 'lst_sort(list, fn)'
- domain-prefix: 3-letter lowercase identifier followee by an underscore
e.g.: err_, lst_, txt_, dta_, map_
e.g.: err_, lst_, txt_, dta_, map_, tts_
- function-name: short, single word if possible, lowercase
- parameter-list: comma separated names or type indicators
@ -258,3 +258,19 @@ SnapExtensions.set(
this.parentThatIsA(StageMorph).worldMap.setHost(name);
}
);
// text-to-speech (tts_):
SnapExtensions.set(
'tts_speak(txt, lang, pitch, rate)',
function (msg, accent, pitch, rate) {
var utter = new SpeechSynthesisUtterance(msg),
isDone = false;
utter.lang = accent;
utter.pitch = pitch;
utter.rate = rate;
utter.onend = () => isDone = true;
window.speechSynthesis.speak(utter);
return () => isDone;
}
);