Intel Edison上の音声ファイルをBluetoothスピーカーを経由して再生してみます。
音声生成APIやセンサーなどと組み合わせることで、簡単な会話ロボットが作れそうです。
環境
wifiなどのセットアップ済みのIntel Edisonを用意します。
検証に使ったファームウェアは以下です。
uname -a
Linux edison 3.10.17-poky-edison+ #1 SMP PREEMPT Wed Apr 29 03:54:01 CEST 2015 i686 GNU/Linux
Bluetoothスピーカーは、以下です。
京ハヤ Bluetooth対応ワイヤレススピーカー
http://www.amazon.co.jp/dp/B00GBXKQHW
TaoTronics Bluetoothは、音声の出だしが切れてしまいうまく動きませんでした。
http://www.amazon.co.jp/gp/product/B00U3IV7JM
Bluetoothの有効化
Edisonは初期状態ではBluetoothがロックされているので、解除します。
rfkill list
-----------
2: bcm43xx Bluetooth: bluetooth
Soft blocked: yes
Hard blocked: no
-----------
rfkill unblock bluetooth
rfkill list
----------
2: bcm43xx Bluetooth: bluetooth
Soft blocked: no
Hard blocked: no
----------
Edisonとスピーカーを接続
次に、bluetoothctlコマンドを使ってスピーカーとBluetoothで接続します。
bluetoothctl
[NEW] Controller 98:4F:EE:XX:XX:XX edison [default]
[bluetooth]# scan on
=>デバイスのスキャンを有効にします。
Discovery started
[CHG] Controller 98:4F:EE:XX:XX:XX Discovering: yes
[NEW] Device 00:23:01:XX:XX:XX JKSP-BT9020
=>目的のデバイスが見つかるはず。
[bluetooth]# pair 30:22:00:XX:XX:XX
=>スピーカとペアリングします。
Attempting to pair with 30:22:00:XX:XX:XX
[CHG] Device 30:22:00:XX:XX:XX Connected: yes
[CHG] Device 30:22:00:XX:XX:XX UUIDs:
0000xxxx-0000-xxx-8000-xxxxxxxxxxxx
0000xxxx-0000-xxx-8000-xxxxxxxxxxxx
0000xxxx-0000-xxx-8000-xxxxxxxxxxxx
0000xxxx-0000-xxx-8000-xxxxxxxxxxxx
0000xxxx-0000-xxx-8000-xxxxxxxxxxxx
[CHG] Device 30:22:00:XX:XX:XX Paired: yes
Pairing successful
[CHG] Device 30:22:00:XX:XX:XX Connected: no
[bluetooth]# connect 30:22:00:XX:XX:XX
=>スピーカへ接続します。
Attempting to connect to 30:22:00:XX:XX:XX
[CHG] Device 30:22:00:XX:XX:XX Connected: yes
Connection successful
[bluetooth]# scan off
=>デバイスのスキャンを無効にします。
[CHG] Device 30:22:00:XX:XX:XX RSSI is nil
Discovery stopped
[CHG] Controller 98:4F:EE:XX:XX:XX Discovering: no
[bluetooth]# quit
=>bluetoothctlコマンドを終了します。
Edisonの音声出力先変更
次にEdisonのデフォルトの音声出力先をBluetoothスピーカーへ変更します。
pactl list sinks | grep Name:
Name: alsa_output.platform-merr_dpcm_dummy.0.analog-stereo
Name: alsa_output.0.analog-stereo
Name: bluez_sink.00_23_01_xx_xx_xx
pactl set-default-sink bluez_sink.00_23_01_xx_xx_xx
音声ファイルの再生にはMPlayerを使うので必要なパッケージなどをインストールしていきます。一部エラーが出たりするが、詳細は調査中...とりあえず手順通りに進めれば動きます。
wget http://www.tortall.net/projects/yasm/releases/yasm-1.3.0.tar.gz
tar xvf yasm-1.3.0.tar.gz
cd yasm-1.3.0
sed -i 's#) ytasm.*#)#' Makefile.in
./configure --prefix=/usr
make
make install
cd
curl http://nonnoise.github.io/Edison/_sources/Edison/base-feeds.conf -o /etc/opkg/base-feeds.conf
curl http://nonnoise.github.io/Edison/_sources/Edison/intel-iotdk.conf -o /etc/opkg/intel-iotdk.conf
curl http://nonnoise.github.io/Edison/_sources/Edison/mraa-upm.conf -o /etc/opkg/mraa-upm.conf
opkg update
opkg install libavahi-client-dev
opkg install pulseaudio
opkg install mpg123
opkg install libpulse
opkg install systemd-dev
opkg install --nodeps jack-dev
opkg install pulseaudio-dev
pkg-config --libs --cflags libpulse
-D_REENTRANT -lpulse
と出力されればOK
MPlayerをインストール
makeに1時間以上かかります...
wget ftp://ftp.mplayerhq.hu/MPlayer/releases/MPlayer-1.1.1.tar.xz
tar xvf MPlayer-1.1.1.tar.xz
cd MPlayer-1.1.1
./configure
make
注)make installがどうしてもこけてしまいます...
原因がわからなかったので一旦諦めて、そのまま使います。
root@edison:~/MPlayer-1.1.1# make install
make -C ffmpeg libpostproc/libpostproc.a
make -C ffmpeg libavfilter/libavfilter.a
make -C ffmpeg libavformat/libavformat.a
install -d /usr/local/bin /usr/local/etc/mplayer /usr/local/lib
make: install: Command not found
Makefile:910: recipe for target 'install-dirs' failed
make: *** [install-dirs] Error 127
MPlayerの設定
mkdir ~/.mplayer
echo "ao=pulse" > ~/.mplayer/config
これで音声ファイルをBluetoothスピーカー経由で再生できるようになります。
./mplayer test.wav
./mplayer test.mp3