From 540b15c4ad73b670d8a47a849bd61a77dced9a25 Mon Sep 17 00:00:00 2001 From: loicbersier Date: Wed, 17 Jul 2019 23:29:29 +0200 Subject: [PATCH] use dectalk locally --- commands/fun/tts/dectalk.js | 35 +++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/commands/fun/tts/dectalk.js b/commands/fun/tts/dectalk.js index ee5e6a8b..74af9cad 100644 --- a/commands/fun/tts/dectalk.js +++ b/commands/fun/tts/dectalk.js @@ -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']}); + }); + } } }