mirror of
https://git.femboyfinancial.jp/james/FemScoreboard.git
synced 2025-11-10 07:43:44 -08:00
Add TTS
This commit is contained in:
43
discord/commands/tts/tts.ts
Normal file
43
discord/commands/tts/tts.ts
Normal file
@@ -0,0 +1,43 @@
|
||||
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
|
||||
};
|
||||
Reference in New Issue
Block a user