From a7f32e593035ded3dd67bdd8cc1a25f08de49330 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Bersier?= Date: Sat, 18 May 2019 03:02:04 +0200 Subject: [PATCH] Microsoft sam --- commands/fun/tts/sam.js | 45 +++++++++++++++++++++++++++++++ commands/fun/tts/samvc.js | 57 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 102 insertions(+) create mode 100644 commands/fun/tts/sam.js create mode 100644 commands/fun/tts/samvc.js diff --git a/commands/fun/tts/sam.js b/commands/fun/tts/sam.js new file mode 100644 index 0000000..94948db --- /dev/null +++ b/commands/fun/tts/sam.js @@ -0,0 +1,45 @@ +const { Command } = require('discord-akairo'); +const axios = require('axios'); +const fs = require('fs'); + +class samCommand extends Command { + constructor() { + super('sam', { + aliases: ['sam'], + category: 'fun', + args: [ + { + id: 'samMessage', + type: 'string', + match: 'rest' + } + ], + description: { + content: 'Send a mp3 of what you wrote in Microsoft Sam tts', + usage: '[text]', + examples: ['Here comes the roflcopter soisoisoisoisoi'] + } + }); + } + + async exec(message, args) { + args.samMessage = args.samMessage.replace('\n', ' '); + args.samMessage = encodeURI(args.samMessage); + + return axios.request({ + responseType: 'arraybuffer', + url: `https://tetyys.com/SAPI4/SAPI4?text=${args.samMessage}&voice=Sam&pitch=100&speed=100`, + method: 'get', + headers: { + 'Content-Type': 'audio/mpeg', + }, + }).then((result) => { + const outputFilename = './sam.mp3'; + fs.writeFileSync(outputFilename, result.data); + return message.channel.send({files: ['./sam.mp3']}); + }); + + } +} + +module.exports = samCommand; \ No newline at end of file diff --git a/commands/fun/tts/samvc.js b/commands/fun/tts/samvc.js new file mode 100644 index 0000000..8decad9 --- /dev/null +++ b/commands/fun/tts/samvc.js @@ -0,0 +1,57 @@ +const { Command } = require('discord-akairo'); +const axios = require('axios'); +const fs = require('fs'); + +class samvcCommand extends Command { + constructor() { + super('samvc', { + aliases: ['samvc'], + category: 'fun', + args: [ + { + id: 'samMessage', + type: 'string', + match: 'rest' + } + ], + description: { + content: 'Repeat what you said in voice chat with Microsoft Sam tts', + usage: '[text]', + examples: ['Here comes the roflcopter soisoisoisoisoi'] + } + }); + } + + async exec(message, args) { + args.samMessage = args.samMessage.replace('\n', ' '); + args.samMessage = encodeURI(args.samMessage); + + return axios.request({ + responseType: 'arraybuffer', + url: `https://tetyys.com/SAPI4/SAPI4?text=${args.samMessage}&voice=Sam&pitch=100&speed=100`, + method: 'get', + headers: { + 'Content-Type': 'audio/mpeg', + }, + }).then(async (result) => { + const outputFilename = './samvc.mp3'; + fs.writeFileSync(outputFilename, result.data); + + const voiceChannel = message.member.voice.channel; + if (!voiceChannel) return message.say('Please enter a voice channel first.'); + try { + const connection = await voiceChannel.join(); + const dispatcher = connection.play('./samvc.wav'); + dispatcher.once('finish', () => voiceChannel.leave()); + dispatcher.once('error', () => voiceChannel.leave()); + return null; + } catch (err) { + voiceChannel.leave(); + return message.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`); + } + }); + + } +} + +module.exports = samvcCommand; \ No newline at end of file