mirror of
https://git.femboyfinancial.jp/james/FemScoreboard.git
synced 2024-11-29 05:02:00 -08:00
44 lines
1.2 KiB
TypeScript
44 lines
1.2 KiB
TypeScript
import {
|
|
AttachmentBuilder,
|
|
ChatInputCommandInteraction,
|
|
SlashCommandBuilder
|
|
} from 'discord.js';
|
|
import 'dotenv/config';
|
|
import { logError, logInfo, logWarn } from '../../../logging';
|
|
import { requestTTSResponse } from '../../util';
|
|
|
|
const config = {
|
|
ttsSettings: {
|
|
pitch_change_oct: 1,
|
|
pitch_change_sem: 0
|
|
}
|
|
};
|
|
|
|
async function ttsCommand(interaction: ChatInputCommandInteraction)
|
|
{
|
|
const text = interaction.options.getString('text');
|
|
await interaction.reply(`generating audio for "${text}"...`);
|
|
try {
|
|
const audio = await requestTTSResponse(text);
|
|
const audioBuf = await audio.arrayBuffer();
|
|
const audioFile = new AttachmentBuilder(Buffer.from(audioBuf)).setName('mikuified.wav');
|
|
await interaction.editReply({
|
|
files: [audioFile]
|
|
});
|
|
} catch (err) {
|
|
await interaction.editReply(`Error: ${err}`);
|
|
logError(`Error while generating TTS: ${err}`);
|
|
}
|
|
}
|
|
|
|
export = {
|
|
data: new SlashCommandBuilder()
|
|
.setName('tts')
|
|
.setDescription('Read text in Miku\'s voice')
|
|
.addStringOption(
|
|
opt => opt.setName('text').setDescription('Text').setRequired(true)
|
|
),
|
|
execute: ttsCommand,
|
|
config: config
|
|
};
|