diff --git a/commands/interaction/tts/texttospeech.js b/commands/interaction/tts/texttospeech.js new file mode 100644 index 0000000..beaedf7 --- /dev/null +++ b/commands/interaction/tts/texttospeech.js @@ -0,0 +1,43 @@ +const { Constants } = require('detritus-client'); +const { InteractionCallbackTypes, ApplicationCommandOptionTypes } = Constants; + +const { imtranslator } = require('../../../labscore/api'); +const { IMTRANSLATOR_VOICES } = require('../../../labscore/constants'); +const { createEmbed } = require('../../../labscore/utils/embed'); +const { icon, highlight } = require('../../../labscore/utils/markdown'); + +module.exports = { + description: 'Text to Speech', + name: 'texttospeech', + options: [ + { + name: 'voice', + description: 'TTS Voice to use', + choices: IMTRANSLATOR_VOICES, + required: true, + }, + { + name: 'text', + description: 'Text', + type: ApplicationCommandOptionTypes.STRING, + required: true, + maxLength: 256 + } + ], + run: async (context, args) => { + try{ + let s = Date.now() + await context.respond({data: {}, type: InteractionCallbackTypes.DEFERRED_CHANNEL_MESSAGE_WITH_SOURCE}) + let audio = await imtranslator(context, args.text, args.voice) + let diff = (Date.now() - s) + await context.editOrRespond({ + embeds: [createEmbed("default", context, { description: `${icon("audio")} Audio Generated in ${highlight(audio.timings + "s")}.` })], + file: { value: audio.response.body, filename: "tts.wav" } + }) + }catch(e){ + await context.editOrRespond({ + embeds: [createEmbed("error", context, "Unable to generate audio file.")] + }) + } + }, +}; \ No newline at end of file diff --git a/commands/interaction/tts/tiktok.js b/commands/interaction/tts/tiktok.js index 55816f4..0e53757 100644 --- a/commands/interaction/tts/tiktok.js +++ b/commands/interaction/tts/tiktok.js @@ -5,7 +5,7 @@ const { tiktok } = require('../../../labscore/api'); const { TIKTOK_VOICES } = require('../../../labscore/constants'); const { createEmbed } = require('../../../labscore/utils/embed'); -const { icon } = require('../../../labscore/utils/markdown'); +const { icon, highlight } = require('../../../labscore/utils/markdown'); module.exports = { description: 'tiktok audio', @@ -32,7 +32,7 @@ module.exports = { let audio = await tiktok(context, args.text, args.voice) await context.editOrRespond({ - embeds: [createEmbed("default", context, { description: `${icon("audio")} Audio Generated in ${audio.timings}` })], + embeds: [createEmbed("default", context, { description: `${icon("audio")} Audio Generated in ${highlight(audio.timings + "s")}.` })], file: { value: audio.response.body, filename: "tiktok.mp3" } })