From 2d956ccddba5ef7b3f48876062a3d584f9845f6b Mon Sep 17 00:00:00 2001 From: uukelele-scratch Date: Wed, 12 Feb 2025 16:26:48 +0000 Subject: [PATCH 1/8] Create speak.js --- src/agent/speak.js | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 src/agent/speak.js diff --git a/src/agent/speak.js b/src/agent/speak.js new file mode 100644 index 0000000..80a36ff --- /dev/null +++ b/src/agent/speak.js @@ -0,0 +1,28 @@ +import { exec } from 'child_process'; + +export function say(textToSpeak) { + const isWin = process.platform === "win32"; + const isMac = process.platform === "darwin"; + + let command; + + if (isWin) { + command = `powershell -Command "Add-Type –AssemblyName System.Speech; (New-Object System.Speech.Synthesis.SpeechSynthesizer).Speak(\\"${textToSpeak}\\")"`; + } else if (isMac) { + command = `say "${textToSpeak}"`; + } else { + command = `espeak "${textToSpeak}"`; + } + + exec(command, (error, stdout, stderr) => { + if (error) { + console.error(`Error: ${error.message}`); + return; + } + if (stderr) { + console.error(`Stderr: ${stderr}`); + return; + } + console.log(`Stdout: ${stdout}`); + }); +} From 043011e20a187671dbebb526d0fa2348d1829b6a Mon Sep 17 00:00:00 2001 From: uukelele-scratch Date: Wed, 12 Feb 2025 16:28:19 +0000 Subject: [PATCH 2/8] Update agent.js --- src/agent/agent.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/agent/agent.js b/src/agent/agent.js index 72eb31d..7012240 100644 --- a/src/agent/agent.js +++ b/src/agent/agent.js @@ -14,6 +14,7 @@ import { addViewer } from './viewer.js'; import settings from '../../settings.js'; import { serverProxy } from './agent_proxy.js'; import { Task } from './tasks.js'; +import { say } from './speak.js'; export class Agent { async start(profile_fp, load_mem=false, init_message=null, count_id=0, task_path=null, task_id=null) { @@ -357,6 +358,7 @@ export class Agent { } } else { + say(message); this.bot.chat(message); } } From 81e4803c229cb6103615a165d8e21b5db98b3bcf Mon Sep 17 00:00:00 2001 From: uukelele-scratch Date: Wed, 12 Feb 2025 18:19:03 +0000 Subject: [PATCH 3/8] Update settings.js --- settings.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/settings.js b/settings.js index 3b6c903..c7c5134 100644 --- a/settings.js +++ b/settings.js @@ -30,7 +30,7 @@ export default "load_memory": false, // load memory from previous session "init_message": "Respond with hello world and your name", // sends to all on spawn "only_chat_with": [], // users that the bots listen to and send general messages to. if empty it will chat publicly - + "speak": true, // allows all bots to speak through system text-to-speech. tested on windows, should work on mac, on linux you may need to `apt install espeak` "language": "en", // translate to/from this language. Supports these language names: https://cloud.google.com/translate/docs/languages "show_bot_views": false, // show bot's view in browser at localhost:3000, 3001... From 9bf70edd102299359ebff69c930e12e0b50386f9 Mon Sep 17 00:00:00 2001 From: uukelele-scratch Date: Wed, 12 Feb 2025 18:33:05 +0000 Subject: [PATCH 4/8] Update agent.js --- src/agent/agent.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/agent/agent.js b/src/agent/agent.js index 7012240..8645344 100644 --- a/src/agent/agent.js +++ b/src/agent/agent.js @@ -358,7 +358,9 @@ export class Agent { } } else { - say(message); + if (settings.speak) { + say(message); + } this.bot.chat(message); } } From e612b00410ec65502596eefcd02b255e56a5519d Mon Sep 17 00:00:00 2001 From: uukelele-scratch Date: Wed, 12 Feb 2025 18:33:57 +0000 Subject: [PATCH 5/8] removed unnecessary debug logging --- src/agent/speak.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/agent/speak.js b/src/agent/speak.js index 80a36ff..946d318 100644 --- a/src/agent/speak.js +++ b/src/agent/speak.js @@ -20,9 +20,8 @@ export function say(textToSpeak) { return; } if (stderr) { - console.error(`Stderr: ${stderr}`); + console.error(`Error: ${stderr}`); return; } - console.log(`Stdout: ${stdout}`); }); } From 4b38aba2dc2b827e17c5bbf37ac844c4f8f753b2 Mon Sep 17 00:00:00 2001 From: uukelele-scratch Date: Wed, 12 Feb 2025 19:10:14 +0000 Subject: [PATCH 6/8] added speaking queue to ensure bot doesn't say multiple things at once --- src/agent/speak.js | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/src/agent/speak.js b/src/agent/speak.js index 946d318..239cb21 100644 --- a/src/agent/speak.js +++ b/src/agent/speak.js @@ -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 }); } From 386900aa03bb4365d8cbed94bfdfa7ab421251c2 Mon Sep 17 00:00:00 2001 From: uukelele-scratch Date: Wed, 12 Feb 2025 19:12:34 +0000 Subject: [PATCH 7/8] removed unnecessary debug logging (again) --- src/agent/speak.js | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/agent/speak.js b/src/agent/speak.js index 239cb21..af18298 100644 --- a/src/agent/speak.js +++ b/src/agent/speak.js @@ -34,12 +34,9 @@ function processQueue() { exec(command, (error, stdout, stderr) => { if (error) { console.error(`Error: ${error.message}`); - console.error(`Stack: ${error.stack}`); + console.error(`${error.stack}`); } else if (stderr) { - console.error(`Stderr: ${stderr}`); - } else { - console.log(`Stdout: ${stdout}`); - } + console.error(`Error: ${stderr}`); processQueue(); // Continue with the next message in the queue }); } From f57da837b1d3eb86a9f7883ba372004e977268ea Mon Sep 17 00:00:00 2001 From: uukelele-scratch Date: Wed, 12 Mar 2025 21:22:14 +0000 Subject: [PATCH 8/8] speaking is now false by default --- settings.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/settings.js b/settings.js index bf35239..b205206 100644 --- a/settings.js +++ b/settings.js @@ -30,7 +30,7 @@ export default "load_memory": false, // load memory from previous session "init_message": "Respond with hello world and your name", // sends to all on spawn "only_chat_with": [], // users that the bots listen to and send general messages to. if empty it will chat publicly - "speak": true, // allows all bots to speak through system text-to-speech. tested on windows, should work on mac, on linux you may need to `apt install espeak` + "speak": false, // allows all bots to speak through system text-to-speech. tested on windows, should work on mac, on linux you may need to `apt install espeak` "language": "en", // translate to/from this language. Supports these language names: https://cloud.google.com/translate/docs/languages "show_bot_views": false, // show bot's view in browser at localhost:3000, 3001...