This commit is contained in:
Daniel O'Connor 2025-02-01 08:56:28 +00:00
commit 9846c8bf9f

View file

@ -77,41 +77,40 @@ export default defineComponent({
} }
}, },
play() { play() {
const self = this;
speechSynthesis.cancel(); speechSynthesis.cancel();
const utterance = new SpeechSynthesisUtterance(this.step.text); const utterance = new SpeechSynthesisUtterance(this.step.text);
utterance.onstart = (event) => { utterance.onstart = (event) => {
self.playing = true; this.playing = true;
self.played = false; this.played = false;
self.paused = false; this.paused = false;
// self.$emit("playing", true); // TODO: Consider if this event should bubble or a proxy of it should. // this.$emit("playing", true); // TODO: Consider if this event should bubble or a proxy of it should.
console.debug("Now playing: " + this.step.text); console.debug("Now playing: " + this.step.text);
}; };
utterance.onend = () => { utterance.onend = () => {
self.playing = false; this.playing = false;
self.played = true; this.played = true;
self.paused = false; this.paused = false;
self.$emit("ttscompleted", true); this.$emit("ttscompleted", true);
console.debug("Playback complete"); console.debug("Playback complete");
}; };
utterance.onpause = () => { utterance.onpause = () => {
self.playing = false; this.playing = false;
self.paused = true; this.paused = true;
}; };
utterance.onresume = () => { utterance.onresume = () => {
self.playing = true; this.playing = true;
self.paused = false; this.paused = false;
}; };
utterance.onboundary = (event) => { utterance.onboundary = (event) => {
// Update the start of the current sentence. // Update the start of the current sentence.
if (event.name === "sentence") { if (event.name === "sentence") {
self.currentIndex = event.charIndex; this.currentIndex = event.charIndex;
} }
}; };
// TODO: Evaluate the usefulness of this event. // TODO: Evaluate the usefulness of this event.