Raspberry PiでBluetoothスピーカーを鳴らす

This text is also text!

Preparation


Amazon.co.jpで買ったEWA A106というスピーカーです

PulseAudioとPulseAudioのBluetoothスピーカーのモジュールをインストールします。

1
sudo apt-get install pulseaudio pulseaudio-module-bluetooth

Setting

PulseAudioの設定


PulseAudioを設定するため、/etc/pulse/default.paを編集します

1
sudo nano /etc/pulse/default.pa

ファイルの最後に次の行を追加します。

1
2
# automatically switch to newly-connected devices
load-module module-switch-on-connect

bluetooth権限追加

sudoなしでBluetoothが制御できるため、ユーザーをbluetoothグループに入れル必要があります。

1
2
sudo usermod -G bluetooth -a $USER
sudo reboot

## 動作
Bluetoothスピーカーをペアリングするためpulseaudioを起動します

1
pulseaudio --start

bluetoothctlコマンドを起動して以下操作します。

1
2
3
4
5
6
7
8
9
$ bluetoothctl
Agent registered
[bluetooth]# power on
Changing power on succeeded
[bluetooth]# scan on
Discovery started
・・・
[NEW] Device 3D:8F:2B:2E:E4:07 EWA Audio A106
・・・

ペアリング

pairコマンドでペアリングします

1
2
[bluetooth]# pair 3D:8F:2B:2E:E4:07
Attempting to pair with 3D:8F:2B:2E:E4:07

Pairing successfulと出れば成功です。
ついでにtrustコマンドでTrustリストに登録します

1
2
3
[bluetooth]# trust 3D:8F:2B:2E:E4:07
[CHG] Device 3D:8F:2B:2E:E4:07 Trusted: yes
Changing 3D:8F:2B:2E:E4:07 trust succeeded

connectコマンドでスピーカーに接続します。

1
2
3
4
5
6
[bluetooth]# connect 3D:8F:2B:2E:E4:07
Attempting to connect to 3D:8F:2B:2E:E4:07
[CHG] Device 3D:8F:2B:2E:E4:07 Connected: yes
Connection successful
[CHG] Device 3D:8F:2B:2E:E4:07 ServicesResolved: yes
[EWA Audio A106]#

終了

以下のコマンドを実行してペアリングを終了します。

1
[EWA Audio A106]# quit

テスト

ファイルを再生して音を鳴らして確認しましょう。

1
$ aplay /usr/share/sounds/alsa/Front_Center.wav

音量調整

alsamixer コマンドで調整できます。
上下キーで音量を調整でき、F6 キーで出力先(ヘッドホンジャック、HDMI など)を変更できます。
また、M ボタンを押すとミュート/ミュート解除の切り替えができます