forked from Supositware/Haha-Yes
someone get me audio working pls
This commit is contained in:
parent
d3630feef9
commit
bf24849b59
1 changed files with 38 additions and 34 deletions
|
@ -25,46 +25,50 @@ class TtsvcCommand extends Command {
|
|||
}
|
||||
|
||||
async exec(message, args) {
|
||||
let text = args.text;
|
||||
try {
|
||||
let text = args.text;
|
||||
|
||||
// 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('ttsvc.mp3', response.audioContent, 'binary', async err => {
|
||||
// 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);
|
||||
message.channel.send('An error has occured, the message is probably too long');
|
||||
|
||||
return;
|
||||
}
|
||||
console.log('Audio content written to file: ttsvc.mp3');
|
||||
|
||||
|
||||
if (message.member.voice.channel) {
|
||||
const connection = await message.member.voice.channel.join();
|
||||
const dispatcher = connection.play('../../ttsvc.mp3');
|
||||
dispatcher.on('finish', () => {
|
||||
dispatcher.destroy();
|
||||
});
|
||||
} else {
|
||||
message.reply('You need to join a voice channel first!');
|
||||
}
|
||||
|
||||
// Write the binary audio content to a local file
|
||||
fs.writeFile('ttsvc.mp3', response.audioContent, 'binary', async err => {
|
||||
if (err) {
|
||||
console.error('ERROR:', err);
|
||||
message.channel.send('An error has occured, the message is probably too long');
|
||||
|
||||
return;
|
||||
}
|
||||
console.log('Audio content written to file: ttsvc.mp3');
|
||||
|
||||
|
||||
if (message.member.voice.channel) {
|
||||
const connection = await message.member.voice.channel.join();
|
||||
const dispatcher = connection.play('../../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;
|
Loading…
Reference in a new issue