Amazon Polly を使って読み上げdiscord botを作った話(1)
Amazon Polly という AWS のサービスが日本語読み上げしてくれるらしい。
と聞いて、node.jsで頑張って作ってみた。
まずは discord 側、VCに入っている人に呼ばれたらその人のところに行く処理。
const Discord = require('discord.js'); const client = new Discord.Client(); const token = "botのトークン"; client.on('ready', () => { console.log('ready...'); }); let text_ch; let voice_ch; let conn; client.on('message', message => { // VCチャンネルの召喚 if (message.content === '!!s') { text_ch = message.channel; voice_ch = message.member.voice.channel; let text = ''; if (voice_ch == undefined) { text = 'VCに入ってから使ってね'; text_ch.send(text) .then(message => console.log(`Sent message: ${text}`)) .catch(console.error); return; } voice_ch.join() .then(connection =>{ conn = connection; }) .catch(console.error); text = 'きたよー'; text_ch.send(text) .then(message => console.log(`Sent message: ${text}`)) .catch(console.error); return; } }); client.login(token);
こんな感じで、"!!s"って呼ばれたVCに入れる。
"!!s"コマンドを打ったテキストチャンネルを保存しているのは、読み上げるときに別のテキストチャンネルを読まなくするため。
とりあえず今日はここまで。