ラズベリーパイで会話したり写真取ったりするロボットを作りたい(準備)¶
はじめに¶
ラズベリーパイに話しかけたら色々してくれるようなものを作りたい。 その準備の覚書。
環境¶
- Raspberry Pi 2 Model B
- NOOBS-RASPBIAN
最初にいろいろ更新¶
sudo apt-get update
sudo apt-get upgrade
sudo rpi-update
sudo reboot
日本語フォントを入れる¶
sudo apt-get install fonts-takeo ibus-mozc
- 再起動
日本語入力できるようにする¶
sudo apt-get install ibus-anthy
- Menu > Preference > RaspberrypiConfig > Locale変更 でメニューを日本語化
- Menu > 設定 > IBus > 入力メソッド > 追加,日本語,Anthy,追加の順
- Menu > 設定 > IBus > 一般 > 入力メソッドをCtrl+Spaceに変更
- これでCtrl+Spaceでメソッド変更できるらしいけどできない
- 全角/半角キー効くから別にいらない
日付を直す¶
- sudo dpkg-reconfigure tzdata
- Asia -> Tokyo を選択
起動後に自動でwifiに接続する¶
そのうちSIMドングルに差し替えたい
手順
ネットワークの確認
wpa_passphrase SSID PASSWORD
network={ ssid="SSID" #psk="PASSWORD" psk="XXXXXXXX" }
サプリエント設定
sudo vi /etc/wpa_supplicant/wpa_supplicant.conf
network={ ssid="SSID" psk="XXXXXXXX" key_mgmt=WPA-PSK proto=WPA pairwise=CCMP group=CCMP priority=2 scan_ssid=1 }
正規カメラモジュールの接続¶
- 設定
- 接続→https://www.raspberrypi.org/help/camera-module-setup/
- コマンド
raspi-config
- 6.Enable camera選択->Enable
- Finish選択で再起動
- 写真を撮ってどこかに送る
raspistill -w 320 -h 240 -o stream.jpg --nopreview
curl -F upload=@stream.jpg http://xxx.yyy.zzz/upload > /dev/null
リモート接続の設定¶
Remote Desktop Protocol : xrdp
sudo apt-get install xrdp
DNS : avahi-daemon
sudo apt-get install avahi-daemon
/etc/hosts に書いてある127.0.1.1:raspberrypi の名前が使える
WindowsからはBonjourが必要なのでiTunesをインストール
raspberrypi.localの名前でリモート接続
デフォルトだとID:pi,PASS:raspberry
キーボードを日本語キーボードにする
cd /etc/xrdp/ sudo wget http://w.vmeta.jp/temp/km-0411.ini sudo ln -s km-0411.ini km-e0010411.ini sudo ln -s km-0411.ini km-e0200411.ini sudo ln -s km-0411.ini km-e0210411.ini
ssh,scpの準備¶
raspberry側
sudo vi /etc/avahi/services/ssh.service
<?xml version="1.0" standalone="no"?> <!DOCTYPE service-group SYSTEM "avahi-service.dtd"> <service-group> <name replace-wildcards="yes">%h</name> <service> <type>_ssh._tcp</type> <port>22</port> </service> </service-group>
sudo /etc/init.d/avahi-daemon restart
ホスト側
ssh pi@raspberry.local
scp XXXX pi@raspberry.local:/home/pi/XXXX
node.jsの準備¶
コマンド¶
nodebrew経由で入れる
$ wget git.io/nodebrew $ perl nodebrew setup $ vi ~/.bashrc 追記:export PATH=$HOME/.nodebrew/current/bin:$PATH $ source ~/.bashrc $ nodebrew install-binary latest
使う
mkdir test & cd $_ npm init npm install express socket.io dateformat jquery request ...
git install¶
sudo apt-get install git
マイクを使う¶
デバイスの優先度を上げる(すでにあるなら編集する)
モジュール確認
sudo cat /proc/asound/modules
/etc/modprobe.d/alsa-base.conf でモジュール読み込み順設定
options snd slots=snd_xxx,snd_usb_audio options snd_usb_audio index=0 options snd_xxxxxxxxx index=1
カード番号を見て環境設定する
arecord -l
export ALSADEV=hw:カード番号
マイク音量を設定する
amixer sset Mic 50 -c 0
(amixer sset Mic 0-62 -c カード番号)
音声認識-Juliusを使う¶
- Julius本体を解凍してインストール
./configure
make
sudo make install
- module組み込み
sudo sh -c "echo snd-pcm-oss >> /etc/modules"
- ほかのモジュールも解凍して使ってみる
julius -C pathToGrammar/testmic.jconf -charconv EUC-JP UTF-8
julius -C pathToDictation/main.jconf -C pathToDictation/am-gmm.jconf -nostrip
音声認識-Juliusを使う2¶
特定のワードのうちどれが使われたか判断する
text.yomi(定義よみを列挙)
ファイルがUTF8,yomi2voca.plがEUCJPなのでコンバートとしてコンバート
iconv -f utf8 -t EUCJP text.yomi | yomi2voca.pl > text.dic
text.jconfを作ってtext.dicを指定する
-w text.dic -v dictation-kit-master/model/lang_m/bccwj.60k.bingram -h dictation-kit-master/model/phone_m/jnas-tri-3k16-gid.binhmm -hlist dictation-kit-master/model/phone_m/logicalTri -n 5 -output 1 -input mic -input oss -rejectshort 500 -charconv euc-jp utf8 -lv 1000
julius -C text.jconf
音声を出させる-AquesTalk¶
- http://www.a-quest.com/products/aquestalkpi.html
- 解凍して置くだけ
alsamixer
音量調節やF6でデバイス変更したりamixer cset numid=3 NUM
NUM=(1:アナログ優先,2:HDMI優先,3:自動)chmod 755 AquesTalkPi
実行できるようにする./AquesTalkPi "漢字も読めます。" | aplay
- USBマイクとUSBスピーカを使う場合
- /etc/modprobe.d/alsa-base.conf でモジュール読み込み順設定
options snd slots=snd_xxx,snd_usb_audio,snd_usb_audio options snd_usb_audio index=0 options snd_usb_audio index=1 options snd_xxxxxxxxx index=2
./AquesTalkPi "漢字も読めます。" | aplay -D plughw:1
- /etc/modprobe.d/alsa-base.conf でモジュール読み込み順設定
写真を撮る¶
- raspistill -t 1 -w 320 -h 240 -o stream.jpg –nopreview
- 1m秒後に320x240サイズの写真をstream.jpgにプレビューなしで保存
写真を送る¶
- AWSにでもnode.jsで待機させとけばいいんじゃないかな
curl -F f=@stream.jpg http://xx.xx.xx.xx:port/upload > /dev/null