Add TTS
This commit is contained in:
@@ -32,6 +32,7 @@ import {
|
||||
openDb,
|
||||
reactionEmojis,
|
||||
recordReaction,
|
||||
requestTTSResponse,
|
||||
sync
|
||||
} from './util';
|
||||
import 'dotenv/config';
|
||||
@@ -166,11 +167,16 @@ async function onNewMessage(message: Message)
|
||||
|
||||
async function fetchMotd()
|
||||
{
|
||||
const res = await fetch(process.env.MOTD_HREF);
|
||||
const xml = await res.text();
|
||||
const parser = new JSDOM(xml);
|
||||
const doc = parser.window.document;
|
||||
return doc.querySelector(process.env.MOTD_QUERY).textContent;
|
||||
try {
|
||||
const res = await fetch(process.env.MOTD_HREF);
|
||||
const xml = await res.text();
|
||||
const parser = new JSDOM(xml);
|
||||
const doc = parser.window.document;
|
||||
const el = doc.querySelector(process.env.MOTD_QUERY);
|
||||
return el ? el.textContent : null;
|
||||
} catch (err) {
|
||||
logWarn('[bot] Failed to fetch MOTD; is the booru down?');
|
||||
}
|
||||
}
|
||||
|
||||
async function requestRVCResponse(src: Attachment): Promise<Blob>
|
||||
@@ -189,7 +195,7 @@ async function requestRVCResponse(src: Attachment): Promise<Blob>
|
||||
const fd = new FormData();
|
||||
fd.append('file', fs.readFileSync(tmpFileName), 'voice-message.ogg');
|
||||
|
||||
const rvcEndpoint = `http://${process.env.LLM_HOST}:${process.env.LLM_PORT}/rvc?${queryParams.toString()}`;
|
||||
const rvcEndpoint = `${process.env.LLM_HOST}/rvc?${queryParams.toString()}`;
|
||||
logInfo(`[bot] Requesting RVC response for ${src.id}`);
|
||||
const res = await fetch(rvcEndpoint, {
|
||||
method: 'POST',
|
||||
@@ -206,7 +212,7 @@ async function requestLLMResponse(messages)
|
||||
for (const field of Object.keys(config["llmconf"].llmSettings)) {
|
||||
queryParams.append(field, config["llmconf"].llmSettings[field]);
|
||||
}
|
||||
const llmEndpoint = `http://${process.env.LLM_HOST}:${process.env.LLM_PORT}/?${queryParams.toString()}`;
|
||||
const llmEndpoint = `${process.env.LLM_HOST}/?${queryParams.toString()}`;
|
||||
const messageList = messages.map((m: Message) => ({
|
||||
role: m.author.bot ? "assistant" : "user",
|
||||
content: m.cleanContent,
|
||||
@@ -244,8 +250,18 @@ async function scheduleRandomMessage(firstTime = false)
|
||||
return;
|
||||
}
|
||||
const randomMessage = await fetchMotd();
|
||||
await channel.send(randomMessage);
|
||||
logInfo(`[bot] Sent MOTD: ${randomMessage}`);
|
||||
if (randomMessage) {
|
||||
const audio = await requestTTSResponse(randomMessage);
|
||||
const audioBuf = await audio.arrayBuffer();
|
||||
const audioFile = new AttachmentBuilder(Buffer.from(audioBuf)).setName('mikuified.wav');
|
||||
await channel.send({
|
||||
content: randomMessage,
|
||||
files: [audioFile]
|
||||
});
|
||||
logInfo(`[bot] Sent MOTD: ${randomMessage}`);
|
||||
} else {
|
||||
logWarn(`[bot] Could not fetch MOTD.`);
|
||||
}
|
||||
}
|
||||
// wait between 2-8 hours
|
||||
const timeoutMins = Math.random() * 360 + 120;
|
||||
|
||||
Reference in New Issue
Block a user