mirror of
https://github.com/kolbytn/mindcraft.git
synced 2025-09-10 03:53:07 +02:00
Merge pull request #441 from uukelele-scratch/main
Added speech functionality for bots
This commit is contained in:
commit
a077ed4151
3 changed files with 47 additions and 1 deletions
|
@ -30,7 +30,7 @@ export default
|
||||||
"load_memory": false, // load memory from previous session
|
"load_memory": false, // load memory from previous session
|
||||||
"init_message": "Respond with hello world and your name", // sends to all on spawn
|
"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
|
"only_chat_with": [], // users that the bots listen to and send general messages to. if empty it will chat publicly
|
||||||
|
"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
|
"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...
|
"show_bot_views": false, // show bot's view in browser at localhost:3000, 3001...
|
||||||
|
|
||||||
|
|
|
@ -14,6 +14,7 @@ import { addViewer } from './viewer.js';
|
||||||
import settings from '../../settings.js';
|
import settings from '../../settings.js';
|
||||||
import { serverProxy } from './agent_proxy.js';
|
import { serverProxy } from './agent_proxy.js';
|
||||||
import { Task } from './tasks.js';
|
import { Task } from './tasks.js';
|
||||||
|
import { say } from './speak.js';
|
||||||
|
|
||||||
export class Agent {
|
export class Agent {
|
||||||
async start(profile_fp, load_mem=false, init_message=null, count_id=0, task_path=null, task_id=null) {
|
async start(profile_fp, load_mem=false, init_message=null, count_id=0, task_path=null, task_id=null) {
|
||||||
|
@ -351,6 +352,9 @@ export class Agent {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
if (settings.speak) {
|
||||||
|
say(message);
|
||||||
|
}
|
||||||
this.bot.chat(message);
|
this.bot.chat(message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
42
src/agent/speak.js
Normal file
42
src/agent/speak.js
Normal file
|
@ -0,0 +1,42 @@
|
||||||
|
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";
|
||||||
|
|
||||||
|
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}`);
|
||||||
|
console.error(`${error.stack}`);
|
||||||
|
} else if (stderr) {
|
||||||
|
console.error(`Error: ${stderr}`);
|
||||||
|
processQueue(); // Continue with the next message in the queue
|
||||||
|
});
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue