mirror of
https://github.com/kolbytn/mindcraft.git
synced 2025-09-10 12:02:59 +02:00
Create speak.js
This commit is contained in:
parent
61586ccfa8
commit
2d956ccddb
1 changed files with 28 additions and 0 deletions
28
src/agent/speak.js
Normal file
28
src/agent/speak.js
Normal file
|
@ -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}`);
|
||||||
|
});
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue