1
0
Fork 0

use local file too

akairo
loicbersier 5 years ago
parent 540b15c4ad
commit 4be84cb798

@ -1,6 +1,6 @@
const { Command } = require('discord-akairo'); const { Command } = require('discord-akairo');
const axios = require('axios'); const util = require('util');
const fs = require('fs'); const exec = util.promisify(require('child_process').exec);
const rand = require('../../../rand.js'); const rand = require('../../../rand.js');
class dectalkvcCommand extends Command { class dectalkvcCommand extends Command {
@ -31,17 +31,12 @@ class dectalkvcCommand extends Command {
args.decMessage = args.decMessage.replace('\n', ' '); args.decMessage = args.decMessage.replace('\n', ' ');
args.decMessage = encodeURI(args.decMessage); args.decMessage = encodeURI(args.decMessage);
return axios.request({ if (process.platform == 'win32') {
responseType: 'arraybuffer', exec(`cd .\\dectalk && .\\say.exe -w dectalk.wav "${args.decMessage}"`)
url: `http://127.0.0.1:8080/api/gen.wav?dectalk=${args.decMessage}`, .catch(err => {
method: 'get', return console.error(err);
headers: { })
'Content-Type': 'audio/wav', .then(async () => {
},
}).then(async (result) => {
const outputFilename = './dectalkvc.wav';
fs.writeFile(outputFilename, result.data, async function(err) {
if (err) console.error(err);
const voiceChannel = message.member.voice.channel; const voiceChannel = message.member.voice.channel;
if (!voiceChannel) return message.say('Please enter a voice channel first.'); if (!voiceChannel) return message.say('Please enter a voice channel first.');
try { try {
@ -55,7 +50,28 @@ class dectalkvcCommand extends Command {
return message.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`); return message.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
} }
}); });
} else if (process.platform == 'linux') {
exec(`wine dectalk/say.exe -w ../../dectalk.wav "${args.decMessage}"`)
.catch(err => {
return console.error(err);
})
.then(async () => {
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('./dectalkvc.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!`);
}
}); });
}
} }
} }

Loading…
Cancel
Save