Skip to content

Commit

Permalink
Queue TTS until preceding message(s) are complete
Browse files Browse the repository at this point in the history
  • Loading branch information
Rosuav committed Jan 6, 2025
1 parent 02a2cfc commit 4589d2e
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions httpstatic/tts_hack.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,23 @@ export function render(data) {
}
}

const queue = [];
DOM("#player").onended = e => {
if (queue.length) {
e.target.src = queue.shift();
e.target.play();
}
};
export function sockmsg_speak(msg) {
DOM("#player").src = msg.tts;
DOM("#player").play();
const pl = DOM("#player");
if (!pl.paused) {
//There's already something playing. Add this one to the queue.
queue.push(msg.tts);
} else {
//Nothing currently playing. Play this immediately.
pl.src = msg.tts;
pl.play();
}
}

on("submit", "#send", e => {
Expand Down

0 comments on commit 4589d2e

Please sign in to comment.