2018-12-08 02:05:18 +01:00
|
|
|
const { Command } = require('discord.js-commando');
|
2018-12-08 20:44:36 +01:00
|
|
|
const textToSpeech = require('@google-cloud/text-to-speech');
|
|
|
|
const gclient = new textToSpeech.TextToSpeechClient();
|
2018-12-08 02:05:18 +01:00
|
|
|
const SelfReloadJSON = require('self-reload-json');
|
2018-12-08 02:25:40 +01:00
|
|
|
const fs = require('fs');
|
2018-12-08 20:44:36 +01:00
|
|
|
|
2018-12-08 02:05:18 +01:00
|
|
|
|
|
|
|
module.exports = class BadMemeCommand extends Command {
|
|
|
|
constructor(client) {
|
|
|
|
super(client, {
|
|
|
|
name: 'tts',
|
|
|
|
group: 'fun',
|
|
|
|
memberName: 'tts',
|
|
|
|
description: `Return what you type in a tts file`,
|
|
|
|
args: [
|
|
|
|
{
|
|
|
|
key: 'text',
|
|
|
|
prompt: 'What do you want to be said',
|
|
|
|
type: 'string',
|
|
|
|
}
|
|
|
|
]
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
async run(message, { text }) {
|
|
|
|
let blacklistJson = new SelfReloadJSON('./json/blacklist.json');
|
|
|
|
if(blacklistJson[message.author.id])
|
|
|
|
return blacklist(blacklistJson[message.author.id] , message)
|
|
|
|
|
2018-12-08 20:44:36 +01:00
|
|
|
// Construct the request
|
|
|
|
const request = {
|
|
|
|
input: {text: text},
|
|
|
|
// Select the language and SSML Voice Gender (optional)
|
|
|
|
voice: {languageCode: 'en-US', ssmlGender: 'NEUTRAL'},
|
|
|
|
// Select the type of audio encoding
|
|
|
|
audioConfig: {audioEncoding: 'MP3'},
|
|
|
|
};
|
|
|
|
|
|
|
|
// Performs the Text-to-Speech request
|
|
|
|
gclient.synthesizeSpeech(request, (err, response) => {
|
|
|
|
if (err) {
|
|
|
|
console.error('ERROR:', err);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Write the binary audio content to a local file
|
|
|
|
fs.writeFile('tts.mp3', response.audioContent, 'binary', err => {
|
|
|
|
if (err) {
|
|
|
|
console.error('ERROR:', err);
|
2018-12-08 21:17:19 +01:00
|
|
|
message.say('An error has occured, the message is probably too long')
|
2018-12-08 20:44:36 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
console.log('Audio content written to file: tts.mp3');
|
2018-12-08 21:10:09 +01:00
|
|
|
message.say({files: ['./tts.mp3']})
|
2018-12-08 02:25:40 +01:00
|
|
|
});
|
|
|
|
});
|
2018-12-08 02:19:36 +01:00
|
|
|
}}
|