|
|
@ -31,11 +31,11 @@ class TtsvcCommand extends Command {
|
|
|
|
|
|
|
|
|
|
|
|
// Construct the request
|
|
|
|
// Construct the request
|
|
|
|
const request = {
|
|
|
|
const request = {
|
|
|
|
input: {text: text},
|
|
|
|
input: { text: text },
|
|
|
|
// Select the language and SSML Voice Gender (optional)
|
|
|
|
// Select the language and SSML Voice Gender (optional)
|
|
|
|
voice: {languageCode: 'en-US', ssmlGender: 'NEUTRAL'},
|
|
|
|
voice: { languageCode: 'en-US', ssmlGender: 'NEUTRAL' },
|
|
|
|
// Select the type of audio encoding
|
|
|
|
// Select the type of audio encoding
|
|
|
|
audioConfig: {audioEncoding: 'MP3'},
|
|
|
|
audioConfig: { audioEncoding: 'MP3' },
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// Performs the Text-to-Speech request
|
|
|
|
// Performs the Text-to-Speech request
|
|
|
@ -49,7 +49,8 @@ class TtsvcCommand extends Command {
|
|
|
|
fs.writeFile('ttsvc.mp3', response.audioContent, 'binary', err => {
|
|
|
|
fs.writeFile('ttsvc.mp3', response.audioContent, 'binary', err => {
|
|
|
|
if (err) {
|
|
|
|
if (err) {
|
|
|
|
console.error('ERROR:', err);
|
|
|
|
console.error('ERROR:', err);
|
|
|
|
message.channel.send('An error has occured, the message is probably too long')
|
|
|
|
message.channel.send('An error has occured, the message is probably too long');
|
|
|
|
|
|
|
|
fs.close();
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
console.log('Audio content written to file: ttsvc.mp3');
|
|
|
|
console.log('Audio content written to file: ttsvc.mp3');
|
|
|
@ -58,19 +59,21 @@ class TtsvcCommand extends Command {
|
|
|
|
if (!voiceChannel) {
|
|
|
|
if (!voiceChannel) {
|
|
|
|
return message.reply('please join a voice channel first!');
|
|
|
|
return message.reply('please join a voice channel first!');
|
|
|
|
|
|
|
|
|
|
|
|
} else
|
|
|
|
} else { // you should be careful in what is included in your scopes, you didn't use the {}
|
|
|
|
// If user say "stop" make the bot leave voice channel
|
|
|
|
// If user say "stop" make the bot leave voice channel
|
|
|
|
if (text == 'stop') {
|
|
|
|
if (text == 'stop') {
|
|
|
|
voiceChannel.leave();
|
|
|
|
voiceChannel.leave();
|
|
|
|
message.channel.send('I leaved the channel');
|
|
|
|
message.channel.send('I leaved the channel');
|
|
|
|
} else
|
|
|
|
} else { // you should be careful in what is included in your scopes, you didn't use the {}
|
|
|
|
voiceChannel.join().then(connection => {
|
|
|
|
voiceChannel.join().then(connection => {
|
|
|
|
const dispatcher = connection.playStream('./ttsvc.mp3');
|
|
|
|
const dispatcher = connection.playStream('./ttsvc.mp3');
|
|
|
|
// End at then end of the audio stream
|
|
|
|
// End at then end of the audio stream
|
|
|
|
dispatcher.on('end', () => setTimeout(function(){
|
|
|
|
dispatcher.on('end', () => setTimeout(function () {
|
|
|
|
voiceChannel.leave();
|
|
|
|
voiceChannel.leave();
|
|
|
|
}, 2000));
|
|
|
|
}, 2000));
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|