From 2d956ccddba5ef7b3f48876062a3d584f9845f6b Mon Sep 17 00:00:00 2001 From: uukelele-scratch Date: Wed, 12 Feb 2025 16:26:48 +0000 Subject: [PATCH] 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}`); + }); +}