Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 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 | 10x 10x 10x 10x 10x 10x 10x 10x 14x 10x 14x 10x 1x 1x 1x 1x 1x | export default class SpeechSynthesis {
constructor(props) {
this.utterance = new window.SpeechSynthesisUtterance();
this.selected = SpeechSynthesis.getVoice(props.voice);
this.utterance.voice = this.selected;
this.utterance.text = props.text.replace(/\n/g, '');
this.utterance.lang = props.lang || 'en-GB';
this.utterance.pitch = parseFloat(props.pitch, 10) || 0.8;
this.utterance.rate = parseFloat(props.rate, 10) || 1;
this.utterance.volume = parseFloat(props.volume, 10) || 1;
}
static supported(selected) {
return window.speechSynthesis;
}
static getVoice(selected) {
const voices = window.speechSynthesis.getVoices();
const voice = voices.find(voice => voice.name === selected);
return voice !== undefined ? voice : voices[0];
}
onend(func) {
this.utterance.onend = func;
}
onerror(func) {
this.utterance.onerror = func;
}
speak() {
window.speechSynthesis.cancel();
window.speechSynthesis.speak(this.utterance);
}
pause() {
window.speechSynthesis.pause();
}
cancel() {
window.speechSynthesis.cancel();
}
resume() {
window.speechSynthesis.resume();
}
}
|