Use new RVC endpoint; more unit tests
This commit is contained in:
@@ -4,7 +4,6 @@
|
||||
*/
|
||||
|
||||
import {
|
||||
Attachment,
|
||||
AttachmentBuilder,
|
||||
Client,
|
||||
Collection,
|
||||
@@ -25,7 +24,6 @@ import {
|
||||
import fs = require('node:fs');
|
||||
import path = require('node:path');
|
||||
import fetch, { Blob as NodeFetchBlob } from 'node-fetch';
|
||||
import FormData = require('form-data');
|
||||
import tmp = require('tmp');
|
||||
import { JSDOM } from 'jsdom';
|
||||
import { logError, logInfo, logWarn } from '../logging';
|
||||
@@ -34,6 +32,7 @@ import {
|
||||
openDb,
|
||||
reactionEmojis,
|
||||
recordReaction,
|
||||
requestRVCResponse,
|
||||
requestTTSResponse,
|
||||
serializeMessageHistory,
|
||||
sync,
|
||||
@@ -354,31 +353,6 @@ async function onNewMessage(message: Message) {
|
||||
}
|
||||
}
|
||||
|
||||
async function requestRVCResponse(src: Attachment): Promise<NodeFetchBlob> {
|
||||
logInfo(`[bot] Downloading audio message ${src.url}`);
|
||||
const srcres = await fetch(src.url);
|
||||
const srcbuf = await srcres.arrayBuffer();
|
||||
const tmpFile = tmp.fileSync();
|
||||
const tmpFileName = tmpFile.name;
|
||||
fs.writeFileSync(tmpFileName, Buffer.from(srcbuf));
|
||||
logInfo(`[bot] Got audio file: ${srcbuf.byteLength} bytes`);
|
||||
|
||||
const queryParams = new URLSearchParams();
|
||||
queryParams.append('token', process.env.LLM_TOKEN || '');
|
||||
|
||||
const fd = new FormData();
|
||||
fd.append('file', fs.readFileSync(tmpFileName), 'voice-message.ogg');
|
||||
|
||||
const rvcEndpoint = `${process.env.RVC_HOST}/rvc?${queryParams.toString()}`;
|
||||
logInfo(`[bot] Requesting RVC response for ${src.id}`);
|
||||
const res = await fetch(rvcEndpoint, {
|
||||
method: 'POST',
|
||||
body: fd,
|
||||
});
|
||||
const resContents = await res.blob();
|
||||
return resContents;
|
||||
}
|
||||
|
||||
async function scheduleRandomMessage(firstTime = false) {
|
||||
if (!firstTime) {
|
||||
if (!process.env.MOTD_CHANNEL) {
|
||||
|
||||
Reference in New Issue
Block a user