forked from Supositware/Haha-Yes
work pls
This commit is contained in:
parent
066be8915e
commit
2bd536aa85
1 changed files with 36 additions and 38 deletions
|
@ -25,50 +25,48 @@ class TtsvcCommand extends Command {
|
||||||
}
|
}
|
||||||
|
|
||||||
async exec(message, args) {
|
async exec(message, args) {
|
||||||
try {
|
let text = args.text;
|
||||||
let text = args.text;
|
|
||||||
|
|
||||||
// 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
|
||||||
gclient.synthesizeSpeech(request, (err, response) => {
|
gclient.synthesizeSpeech(request, (err, response) => {
|
||||||
|
if (err) {
|
||||||
|
console.error('ERROR:', err);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Write the binary audio content to a local file
|
||||||
|
fs.writeFile('ttsvc.mp3', response.audioContent, 'binary', async 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');
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
console.log('Audio content written to file: ttsvc.mp3');
|
||||||
// Write the binary audio content to a local file
|
|
||||||
fs.writeFile('ttsvc.mp3', response.audioContent, 'binary', async err => {
|
const voiceChannel = message.member.voice.channel;
|
||||||
if (err) {
|
if (!voiceChannel) return message.say('Please enter a voice channel first.');
|
||||||
console.error('ERROR:', err);
|
try {
|
||||||
message.channel.send('An error has occured, the message is probably too long');
|
const connection = await voiceChannel.join();
|
||||||
|
const dispatcher = connection.play('../../ttsvc.mp3');
|
||||||
return;
|
dispatcher.once('finish', () => voiceChannel.leave());
|
||||||
}
|
dispatcher.once('error', () => voiceChannel.leave());
|
||||||
console.log('Audio content written to file: ttsvc.mp3');
|
return null;
|
||||||
|
} catch (err) {
|
||||||
|
voiceChannel.leave();
|
||||||
if (message.member.voice.channel) {
|
return message.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
|
||||||
const connection = await message.member.voice.channel.join();
|
}
|
||||||
const dispatcher = connection.playFile('../../ttsvc.mp3');
|
|
||||||
dispatcher.on('finish', () => {
|
|
||||||
dispatcher.destroy();
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
message.reply('You need to join a voice channel first!');
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
} catch (err) {
|
});
|
||||||
console.error(err);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
module.exports = TtsvcCommand;
|
module.exports = TtsvcCommand;
|
Loading…
Reference in a new issue