added speaking queue to ensure bot doesn't say multiple things at once

This commit is contained in:
uukelele-scratch 2025-02-12 19:10:14 +00:00 committed by GitHub
parent e612b00410
commit 4b38aba2dc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1,6 +1,23 @@
import { exec } from 'child_process';
let speakingQueue = [];
let isSpeaking = false;
export function say(textToSpeak) {
speakingQueue.push(textToSpeak);
if (!isSpeaking) {
processQueue();
}
}
function processQueue() {
if (speakingQueue.length === 0) {
isSpeaking = false;
return;
}
isSpeaking = true;
const textToSpeak = speakingQueue.shift();
const isWin = process.platform === "win32";
const isMac = process.platform === "darwin";
@ -17,11 +34,12 @@ export function say(textToSpeak) {
exec(command, (error, stdout, stderr) => {
if (error) {
console.error(`Error: ${error.message}`);
return;
}
if (stderr) {
console.error(`Error: ${stderr}`);
return;
console.error(`Stack: ${error.stack}`);
} else if (stderr) {
console.error(`Stderr: ${stderr}`);
} else {
console.log(`Stdout: ${stdout}`);
}
processQueue(); // Continue with the next message in the queue
});
}