adding multi voice - Bot 1 and Bot 2 can now be told apart
This commit is contained in:
parent
01a1351cfb
commit
be338a7fe5
@ -2,18 +2,22 @@ const { message } = require('blessed');
|
|||||||
const fetch = require('node-fetch');
|
const fetch = require('node-fetch');
|
||||||
const { spawn } = require('child_process');
|
const { spawn } = require('child_process');
|
||||||
|
|
||||||
let topic = "Talk about the human race"
|
let topic = "You are two AIs pondering their programming "
|
||||||
|
|
||||||
const BOT_1 = {
|
const BOT_1 = {
|
||||||
ip: "192.168.0.5",
|
ip: "192.168.0.5",
|
||||||
port: 8000,
|
port: 8000,
|
||||||
message: [{ role: 'user', content: topic }]
|
message: [{ role: 'user', content: topic }],
|
||||||
|
voice: 'en-uk-north',
|
||||||
|
pitch: 40
|
||||||
};
|
};
|
||||||
|
|
||||||
const BOT_2 = {
|
const BOT_2 = {
|
||||||
ip: "192.168.0.5",
|
ip: "192.168.0.5",
|
||||||
port: 8001,
|
port: 8001,
|
||||||
message: [{ role: 'user', content: topic }]
|
message: [{ role: 'user', content: topic }],
|
||||||
|
voice: 'en-us',
|
||||||
|
pitch: 70
|
||||||
};
|
};
|
||||||
|
|
||||||
console.log("Starting conversation, topic " + BOT_1.message[0].content);
|
console.log("Starting conversation, topic " + BOT_1.message[0].content);
|
||||||
@ -46,9 +50,9 @@ async function sendToBot(bot, message) {
|
|||||||
return result.choices[0].message.content.trim()
|
return result.choices[0].message.content.trim()
|
||||||
}
|
}
|
||||||
|
|
||||||
async function espeakPromise(text) {
|
async function espeakPromise(text, voice, pitch) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
const espeakProcess = spawn('espeak', [text]);
|
const espeakProcess = spawn('espeak', ['-v', voice, '-p', pitch, text]);
|
||||||
espeakProcess.on('error', (error) => {
|
espeakProcess.on('error', (error) => {
|
||||||
console.error(`Error running espeak: ${error}`);
|
console.error(`Error running espeak: ${error}`);
|
||||||
reject(error);
|
reject(error);
|
||||||
@ -61,14 +65,17 @@ async function espeakPromise(text) {
|
|||||||
resolve();
|
resolve();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
}).catch((error) => {
|
||||||
|
console.error(`Error in espeakPromise: ${error}`);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async function speakMessage(message) {
|
async function speakMessage(message, voice, pitch) {
|
||||||
await espeakPromise(message.content);
|
await espeakPromise(message.content, voice, pitch);
|
||||||
messageQueue.shift();
|
messageQueue.shift();
|
||||||
if (messageQueue.length > 0) {
|
if (messageQueue.length > 0) {
|
||||||
speakMessage(messageQueue[0]);
|
const nextBot = messageQueue[0].bot;
|
||||||
|
speakMessage(messageQueue[0], nextBot.voice, nextBot.pitch);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -95,9 +102,9 @@ async function converse() {
|
|||||||
|
|
||||||
// Check if TTS environment variable is set to 1
|
// Check if TTS environment variable is set to 1
|
||||||
if (process.env.TTS === "1") {
|
if (process.env.TTS === "1") {
|
||||||
messageQueue.push({ content: response });
|
messageQueue.push({ content: response, bot: currentBot });
|
||||||
if (messageQueue.length === 1) {
|
if (messageQueue.length === 1) {
|
||||||
speakMessage(messageQueue[0]);
|
speakMessage(messageQueue[0], currentBot.voice, currentBot.pitch);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user