Use new RVC endpoint; more unit tests
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
*/
|
||||
|
||||
import {
|
||||
Attachment,
|
||||
Collection,
|
||||
GuildManager,
|
||||
GuildTextBasedChannel,
|
||||
@@ -13,12 +14,14 @@ import {
|
||||
User,
|
||||
} from 'discord.js';
|
||||
import { get as getEmojiName } from 'emoji-unicode-map';
|
||||
import { createWriteStream, existsSync, unlinkSync } from 'fs';
|
||||
import { createWriteStream, existsSync, readFileSync, unlinkSync, writeFileSync } from 'fs';
|
||||
import { get as httpGet } from 'https';
|
||||
import { Database, open } from 'sqlite';
|
||||
import { Database as Database3 } from 'sqlite3';
|
||||
import 'dotenv/config';
|
||||
import FormData = require('form-data');
|
||||
import fetch, { Blob as NodeFetchBlob } from 'node-fetch';
|
||||
import tmp = require('tmp');
|
||||
import { logError, logInfo, logWarn } from '../logging';
|
||||
import { ScoreboardMessageRow } from '../models';
|
||||
import { LLMDiscordMessage } from './provider/provider';
|
||||
@@ -331,12 +334,37 @@ async function requestTTSResponse(
|
||||
return resContents;
|
||||
}
|
||||
|
||||
async function requestRVCResponse(src: Attachment, pitch?: number): 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;
|
||||
writeFileSync(tmpFileName, Buffer.from(srcbuf));
|
||||
logInfo(`[bot] Got audio file: ${srcbuf.byteLength} bytes`);
|
||||
|
||||
const fd = new FormData();
|
||||
fd.append('input_audio', readFileSync(tmpFileName), 'voice-message.ogg');
|
||||
fd.append('modelpath', 'model.pth');
|
||||
fd.append('f0_up_key', pitch ?? 0);
|
||||
|
||||
const rvcEndpoint = `${process.env.RVC_HOST}/inference`;
|
||||
logInfo(`[bot] Requesting RVC response for ${src.id}`);
|
||||
const res = await fetch(rvcEndpoint, {
|
||||
method: 'POST',
|
||||
body: fd,
|
||||
});
|
||||
const resContents = await res.blob();
|
||||
return resContents;
|
||||
}
|
||||
|
||||
export {
|
||||
db,
|
||||
clearDb,
|
||||
openDb,
|
||||
reactionEmojis,
|
||||
recordReaction,
|
||||
requestRVCResponse,
|
||||
requestTTSResponse,
|
||||
serializeMessageHistory,
|
||||
sync,
|
||||
|
||||
Reference in New Issue
Block a user