環境
- OS: Ubuntu 18.04.3 LTS (Bionic Beaver)
- Hardware: Raspberry Pi 3B+
- Android端末: Essential Phone PH-1, HUAWEI nova
Android端末 --Bluetooth--> Raspberry Pi --USB--> スピーカー
PulseAudio経由で音を出す
皆さんPulseAudio経由でA2DP環境を構築しているようです。
http://temama.hatenablog.com/entry/2019/06/21/114751
上の記事が大変参考になります。
しかし、私の環境では以下のようにBluetooth接続後すぐ切断する症状がでてしまいました。
$ sudo bluetoothctl
[bluetooth]# discoverable on
...
[CHG] Device XX:XX:XX:XX:XX:XX Connected: yes
[CHG] Device XX:XX:XX:XX:XX:XX Connected: no
[bluetooth]#
bluetooth disconnect immediately
的なキーワードで調べても、Ubuntu起因なのかラズパイ起因なのかすらわからず、結局諦めました。bluezをダウングレードしろだとかいろいろ意見が飛び交っていましたが、どれも解決には至りませんでした。
オススメの方法
そこでオススメなのが、以下のプロジェクトを使う方法です。
https://github.com/nicokaiser/rpi-audio-receiver
sudo apt update -y
sudo apt upgrade -y
sudo apt install -y --no-install-recommends git
git clone https://github.com/nicokaiser/rpi-audio-receiver.git
cd rpi-audio-receiver
./install.sh
...
Do you want to install Bluetooth Audio (BlueALSA)? [y/N] y
...
上のようにインストールしてください。BlueALSA
以外は不要なのでお好みで。
サービスが作成されているので、以下のように起動します。
sudo systemctl start bluetooth-agent.service
あとは、普通にbluetoothctl
を使って接続するだけ。
$ sudo bluetoothctl
[bluetooth]# discoverable on
[bluetooth]# trust XX:XX:XX:XX:XX:XX
Ubuntuの場合
以下の手順が必要になると思います。
https://github.com/Arkq/bluez-alsa
上記プロジェクトをmake install
raspi-config
なるコマンドはUbuntuになかったので、コメントアウト。
https://github.com/nicokaiser/rpi-audio-receiver/blob/2647fa3bea333d0be65f49796bc3c712d0bf5455/install.sh#L4
bluealsa
なるパッケージがなかったので、上で手動インストールしました。そのため、bluealsa
だけ削除。
https://github.com/nicokaiser/rpi-audio-receiver/blob/2647fa3bea333d0be65f49796bc3c712d0bf5455/install-bluetooth.sh#L7
また、hci0
をhci1
に一括置換。
/usr/bin/hciconfig
を/bin/hciconfig
に変更。
https://github.com/nicokaiser/rpi-audio-receiver/blob/2647fa3bea333d0be65f49796bc3c712d0bf5455/install-bluetooth.sh#L148
https://github.com/nicokaiser/rpi-audio-receiver/blob/2647fa3bea333d0be65f49796bc3c712d0bf5455/install-bluetooth.sh#L149
以上です。