2025-02-12 16:26:48 +00:00
|
|
|
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) {
|
2025-02-12 18:33:57 +00:00
|
|
|
console.error(`Error: ${stderr}`);
|
2025-02-12 16:26:48 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|