mirror of
https://github.com/kolbytn/mindcraft.git
synced 2025-08-28 18:03:03 +02:00
added speaking queue to ensure bot doesn't say multiple things at once
This commit is contained in:
parent
e612b00410
commit
4b38aba2dc
1 changed files with 23 additions and 5 deletions
|
@ -1,6 +1,23 @@
|
||||||
import { exec } from 'child_process';
|
import { exec } from 'child_process';
|
||||||
|
|
||||||
|
let speakingQueue = [];
|
||||||
|
let isSpeaking = false;
|
||||||
|
|
||||||
export function say(textToSpeak) {
|
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 isWin = process.platform === "win32";
|
||||||
const isMac = process.platform === "darwin";
|
const isMac = process.platform === "darwin";
|
||||||
|
|
||||||
|
@ -17,11 +34,12 @@ export function say(textToSpeak) {
|
||||||
exec(command, (error, stdout, stderr) => {
|
exec(command, (error, stdout, stderr) => {
|
||||||
if (error) {
|
if (error) {
|
||||||
console.error(`Error: ${error.message}`);
|
console.error(`Error: ${error.message}`);
|
||||||
return;
|
console.error(`Stack: ${error.stack}`);
|
||||||
}
|
} else if (stderr) {
|
||||||
if (stderr) {
|
console.error(`Stderr: ${stderr}`);
|
||||||
console.error(`Error: ${stderr}`);
|
} else {
|
||||||
return;
|
console.log(`Stdout: ${stdout}`);
|
||||||
}
|
}
|
||||||
|
processQueue(); // Continue with the next message in the queue
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue