Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ Voicebox対応 #46

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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);
}


Expand Down Expand Up @@ -150,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('')
Expand All @@ -170,6 +174,8 @@ function replaceString(mes) {
mes = mes.split('!').join('')
mes = mes.split('`').join('')

console.log(mes);

return mes;
}

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
46 changes: 46 additions & 0 deletions voicebox.js
Original file line number Diff line number Diff line change
@@ -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;
}
};
28 changes: 19 additions & 9 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down