From 8c840464629fe836760aa8344e57df0ca1385f43 Mon Sep 17 00:00:00 2001 From: chipsnet Date: Wed, 25 May 2022 22:31:58 +0900 Subject: [PATCH 1/2] =?UTF-8?q?=E2=9C=A8=20Voicebox=E5=AF=BE=E5=BF=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- index.js | 3 +++ package.json | 2 +- voicebox.js | 46 ++++++++++++++++++++++++++++++++++++++++++++++ yarn.lock | 28 +++++++++++++++++++--------- 4 files changed, 69 insertions(+), 10 deletions(-) create mode 100644 voicebox.js diff --git a/index.js b/index.js index f2f52db..6d84811 100644 --- a/index.js +++ b/index.js @@ -3,6 +3,7 @@ const packageJson = require('./package.json'); const fs = require('fs'); const OpenJtalk = require('./openjtalk') const Softalk = require('./softalk') +const Voicebox = require('./voicebox') const update = require('./update') const Discord = require('discord.js'); const yaml = require("js-yaml"); @@ -45,6 +46,8 @@ if (useVoiceClient == 1) { voiceClient = new Softalk(log); } else if (useVoiceClient == 2) { voiceClient = new OpenJtalk(log); +} else if (useVoiceClient == 3) { + voiceClient = new Voicebox(log); } diff --git a/package.json b/package.json index d7f0947..f8c0104 100644 --- a/package.json +++ b/package.json @@ -11,7 +11,7 @@ }, "dependencies": { "@discordjs/opus": "^0.5.3", - "axios": "^0.25.0", + "axios": "^0.27.2", "bunyan": "^1.8.15", "chokidar": "^3.5.2", "discord.js": "^12.5.3", diff --git a/voicebox.js b/voicebox.js new file mode 100644 index 0000000..52f5ab4 --- /dev/null +++ b/voicebox.js @@ -0,0 +1,46 @@ +const fs = require("fs/promises"); +const axios = require("axios"); +const { execFile } = require("child_process"); +const chokidar = require("chokidar"); +const Encoding = require("encoding-japanese"); + +module.exports = class { + constructor(log) { + this.log = log.child({ module: "voicebox" }); + } + + async createVoice(message) { + this.log.debug("๐ŸŽค Voiceboxใง้Ÿณๅฃฐใ‚’็”Ÿๆˆใ—ใพใ™:", message); + + const queryRes = await axios.post( + "http://localhost:50021/audio_query", + null, + { + params: { + speaker: 1, + text: message, + }, + } + ); + + const audioRes = await axios.post( + "http://localhost:50021/synthesis", + queryRes.data, + { + responseType: 'arraybuffer', + params: { + speaker: 1, + }, + headers: { + "accept": "audio/wav" + } + } + ); + + await fs.writeFile("./voice.wav", new Buffer.from(audioRes.data), 'binary'); + + this.log.debug("โœ… ็”Ÿๆˆๅ‡ฆ็†ใŒๅฎŒไบ†ใ—ใพใ—ใŸ"); + + return; + } +}; diff --git a/yarn.lock b/yarn.lock index da0ace3..c2ef258 100644 --- a/yarn.lock +++ b/yarn.lock @@ -145,12 +145,13 @@ asynckit@^0.4.0: resolved "https://registry.yarnpkg.com/asynckit/-/asynckit-0.4.0.tgz#c79ed97f7f34cb8f2ba1bc9790bcc366474b4b79" integrity sha1-x57Zf380y48robyXkLzDZkdLS3k= -axios@^0.25.0: - version "0.25.0" - resolved "https://registry.yarnpkg.com/axios/-/axios-0.25.0.tgz#349cfbb31331a9b4453190791760a8d35b093e0a" - integrity sha512-cD8FOb0tRH3uuEe6+evtAbgJtfxr7ly3fQjYcMcuPlgkwVS9xboaVIpcDV+cYQe+yGykgwZCs1pzjntcGa6l5g== +axios@^0.27.2: + version "0.27.2" + resolved "https://registry.yarnpkg.com/axios/-/axios-0.27.2.tgz#207658cc8621606e586c85db4b41a750e756d972" + integrity sha512-t+yRIyySRTp/wua5xEr+z1q60QmLq8ABsS5O9Me1AsE5dfKqgnCFzwiCZZ/cGNd1lq4/7akDWMxdhVlucjmnOQ== dependencies: - follow-redirects "^1.14.7" + follow-redirects "^1.14.9" + form-data "^4.0.0" balanced-match@^1.0.0: version "1.0.2" @@ -468,10 +469,19 @@ fill-range@^7.0.1: dependencies: to-regex-range "^5.0.1" -follow-redirects@^1.14.7: - version "1.14.7" - resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.14.7.tgz#2004c02eb9436eee9a21446a6477debf17e81685" - integrity sha512-+hbxoLbFMbRKDwohX8GkTataGqO6Jb7jGwpAlwgy2bIz25XtRm7KEzJM76R1WiNT5SwZkX4Y75SwBolkpmE7iQ== +follow-redirects@^1.14.9: + version "1.15.0" + resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.15.0.tgz#06441868281c86d0dda4ad8bdaead2d02dca89d4" + integrity sha512-aExlJShTV4qOUOL7yF1U5tvLCB0xQuudbf6toyYA0E/acBNw71mvjFTnLaRp50aQaYocMR0a/RMMBIHeZnGyjQ== + +form-data@^4.0.0: + version "4.0.0" + resolved "https://registry.yarnpkg.com/form-data/-/form-data-4.0.0.tgz#93919daeaf361ee529584b9b31664dc12c9fa452" + integrity sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww== + dependencies: + asynckit "^0.4.0" + combined-stream "^1.0.8" + mime-types "^2.1.12" fs-minipass@^2.0.0: version "2.1.0" From 38737d9ad35af0fb53905cca1bf55c3340991979 Mon Sep 17 00:00:00 2001 From: chipsnet Date: Sat, 28 May 2022 14:27:24 +0900 Subject: [PATCH 2/2] =?UTF-8?q?=E2=9C=A8=20=E3=82=B3=E3=83=BC=E3=83=89?= =?UTF-8?q?=E3=83=96=E3=83=AD=E3=83=83=E3=82=AF=E3=81=AF=E8=AA=AD=E3=81=BE?= =?UTF-8?q?=E3=81=AA=E3=81=84=E3=82=88=E3=81=86=E3=81=AB=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- index.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/index.js b/index.js index 6d84811..1b40de9 100644 --- a/index.js +++ b/index.js @@ -153,6 +153,7 @@ function replaceString(mes) { mes = mes.replace(/:.*?:/g, "") mes = mes.replace(/\|\|.*?\|\|/g, "ไผใ›ๅญ—") mes = mes.replace(/(https?:\/\/[\x21-\x7e]+)/g, "ใ‚†ใƒผใ‚ใƒผใ‚‹ใˆใ‚‹") + mes = mes.replace(/```[^]+?```/g, "") mes = mes.split('|').join('') mes = mes.split(';').join('') @@ -173,6 +174,8 @@ function replaceString(mes) { mes = mes.split('!').join('') mes = mes.split('`').join('') + console.log(mes); + return mes; }