LoginSignup
2
4

More than 3 years have passed since last update.

スマホをBluetoothで Raspberry Pi 3B+ に接続、ラズパイに繋いだスピーカーから音を出す

Posted at

環境

  • 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
また、hci0hci1に一括置換。

/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

以上です。

2
4
0

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
2
4