36
39

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Slackの投稿内容を読み上げる

Posted at

先日開催されたIoT縛りの勉強会! IoTLT vol.1にて、IoT ChatOpsという内容で発表しました。そのときの発表の最後に使ったネタです。Slackで投稿した内容をbotが読み上げてくれます。

必要なもの

  • Raspberry Pi (Model Bで確認)
  • Wi-Fiモジュール
  • スピーカー

手順

RasPiセットアップ

いつもどおりRasPiをセットアップ、node.jsのインストールを済ませて置きます。

RaspberryPiに喋らせる

全般的にコチラの記事を参考にさせて頂きました。hubotが受けたメッセージを、OpenJTalkというOSSで日本語対応の音声合成エンジンを使用してスピーカー出力しています。
http://shokai.org/blog/archives/6893

OpenJTalkのインストール

sudo apt-get install open-jtalk open-jtalk-mecab-naist-jdic htsengine libhtsengine-dev hts-voice-nitech-jp-atr503-m001

jsayというシェルを作成してホーム(/home/pi)に置きます。hubot上でこのディレクトリを直指定しているので場所が違うと動きません。

#!/bin/sh
TMP=/tmp/jsay.wav
#cd /usr/share/hts-voice/nitech-jp-atr503-m001
cd /usr/share/hts-voice/mei_happy
echo "$1" | open_jtalk \
-td tree-dur.inf \
-tf tree-lf0.inf \
-tm tree-mgc.inf \
-md dur.pdf \
-mf lf0.pdf \
-mm mgc.pdf \
-dm mgc.win1 \
-dm mgc.win2 \
-dm mgc.win3 \
-df lf0.win1 \
-df lf0.win2 \
-df lf0.win3 \
-dl lpf.win1 \
-ef tree-gv-lf0.inf \
-em tree-gv-mgc.inf \
-cf gv-lf0.pdf \
-cm gv-mgc.pdf \
-k gv-switch.inf \
-s 16000 \
-a 0.05 \
-u 0.0 \
-jm 1.0 \
-jf 1.0 \
-jl 1.0 \
-x /var/lib/mecab/dic/open-jtalk/naist-jdic \
-ow $TMP && \
aplay --quiet $TMP
rm -f $TMP

hubotを動かす

次のレポジトリからcloneしてきて下さい。
https://github.com/KeitaMoromizato/slack-speaker

Slackの設定からtokenを取得し、cloneしたレポジトリにあるファイルに埋め込みます。

bin/hubot
set -e

npm install
export PATH="node_modules/.bin:node_modules/hubot/node_modules/.bin:$PATH"
export HUBOT_SLACK_TOKEN= //ここを書き換える

forever start -c coffee node_modules/.bin/hubot -a slack

# exec node_modules/.bin/hubot "$@"

hubot起動

自動起動

この記事で書いた用にhubotを自動起動したい場合はnpmでforeverをインストール、init.dをゴチャゴチャいじります。これで再起動したら起動しているはずなので、Slackにbotをinviteして試してみてください。

手動起動

手動起動する場合は、先ほどのシェルを少々修正して

bin/hubot
# ここをコメントアウト
# forever start -c coffee node_modules/.bin/hubot -a slack

# ここのコメントアウトを解除
exec node_modules/.bin/hubot "$@"

次のコマンドで起動します

./bin/hubot -a slack

最後に

正直ネタ以外に使い道が分かりません...

36
39
3

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
36
39

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?