forked from Supositware/Haha-Yes
use dectalk locally
This commit is contained in:
parent
5b61bdc74d
commit
540b15c4ad
1 changed files with 19 additions and 16 deletions
|
@ -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 dectalkCommand extends Command {
|
class dectalkCommand extends Command {
|
||||||
|
@ -29,21 +29,24 @@ class dectalkCommand extends Command {
|
||||||
async exec(message, args) {
|
async exec(message, args) {
|
||||||
args.decMessage = rand.random(args.decMessage, message);
|
args.decMessage = rand.random(args.decMessage, message);
|
||||||
args.decMessage = args.decMessage.replace('\n', ' ');
|
args.decMessage = args.decMessage.replace('\n', ' ');
|
||||||
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(() => {
|
||||||
},
|
return message.channel.send({files: ['./dectalk/dectalk.wav']});
|
||||||
}).then((result) => {
|
|
||||||
const outputFilename = './dectalk.wav';
|
|
||||||
fs.writeFileSync(outputFilename, result.data);
|
|
||||||
return message.channel.send({files: ['./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']});
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue