use dectalk locally

This commit is contained in:
loicbersier 2019-07-17 23:29:29 +02:00
parent 5b61bdc74d
commit 540b15c4ad

View file

@ -1,6 +1,6 @@
const { Command } = require('discord-akairo');
const axios = require('axios');
const fs = require('fs');
const util = require('util');
const exec = util.promisify(require('child_process').exec);
const rand = require('../../../rand.js');
class dectalkCommand extends Command {
@ -29,21 +29,24 @@ class dectalkCommand extends Command {
async exec(message, args) {
args.decMessage = rand.random(args.decMessage, message);
args.decMessage = args.decMessage.replace('\n', ' ');
args.decMessage = encodeURI(args.decMessage);
return axios.request({
responseType: 'arraybuffer',
url: `http://127.0.0.1:8080/api/gen.wav?dectalk=${args.decMessage}`,
method: 'get',
headers: {
'Content-Type': 'audio/wav',
},
}).then((result) => {
const outputFilename = './dectalk.wav';
fs.writeFileSync(outputFilename, result.data);
return message.channel.send({files: ['./dectalk.wav']});
});
if (process.platform == 'win32') {
exec(`cd .\\dectalk && .\\say.exe -w dectalk.wav "${args.decMessage}"`)
.catch(err => {
return console.error(err);
})
.then(() => {
return message.channel.send({files: ['./dectalk/dectalk.wav']});
});
} else if (process.platform == 'linux') {
exec(`wine dectalk/say.exe -w ../../dectalk.wav "${args.decMessage}"`)
.catch(err => {
return console.error(err);
})
.then(() => {
return message.channel.send({files: ['./dectalk/dectalk.wav']});
});
}
}
}