LoginSignup
17
22

More than 5 years have passed since last update.

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

Last updated at Posted at 2019-01-04

概要

スピーカーをRaspberry PiとBluetooth接続し、オーディオ出力する。
また、おまけとして、Raspberry Piでサイマルラジオを受信し、Bluetooth接続したスピーカーで再生する。

環境

  • Raspberry Pi本体 ※Bluetooth内蔵モデル(Pi Zero W)が望ましい
  • SDカード ※Raspbian Stretch Liteにsshdを導入済みの4GB以上のもの
  • Micro USB Micro-Bケーブル、または、Pi Zero USB Stem ※Raspberry Pi本体への電源供給方法
  • Bluetooth Audio Receiverデバイス(MR230) ※以下、Bluetoothデバイス
  • スピーカー ※3.5mmステレオミニプラグ(オス)入力対応

手順

  1. Raspberry PiとBluetoothデバイスをペアリングする。

    $ sudo bluetoothctl
    [bluetooth]# scan on
    [bluetooth]# scan off
    [bluetooth]# trust E8:07:BF:xx:xx:xx
    [bluetooth]# pair E8:07:BF:xx:xx:xx
    [bluetooth]# connect E8:07:BF:xx:xx:xx
    [MR230]# paired-devices
    [MR230]# quit
    
  2. BluetoothデバイスをALSAデバイスとして扱えるよう、Bluetooth Audio ALSA Backend(以下、bluez-alsa)を導入する。

    $ sudo apt install bluealsa
    
  3. ~/.asoundrcファイルにBluetoothデバイスを別名定義(bluealsaとbt-receiver)する。

    $ vi ~/.asoundrc
    defaults.bluealsa.interface "hci0"
    defaults.bluealsa.device "E8:07:BF:xx:xx:xx"
    defaults.bluealsa.profile "a2dp"
    defaults.bluealsa.delay 10000
    
    pcm.bt-receiver {
      type bluealsa
      device "E8:07:BF:F0:2F:31"
      profile "a2dp"
    }
    
  4. bluez-alsaがBluetoothデバイスを認識していることを確認する。

    $ amixer -D bluealsa
    Simple mixer control 'MR230 - A2DP',0
    Capabilities: pvolume pswitch
    Playback channels: Front Left - Front Right
    Limits: Playback 0 - 127
    Mono:
    Front Left: Playback 127 [100%] [on]
    Front Right: Playback 127 [100%] [on]
    
  5. Simple mixer controlに続く文字列はBluetoothデバイスの識別子となるため、書き留めておくこと。ここでは、'MR230 - A2DP'である。

  6. Bluetoothデバイス'MR230 - A2DP'のボリュームを70%に変更する。

    $ amixer -D bluealsa sset 'MR230 - A2DP' 70%
    
  7. mplayerコマンドをインストールする。

    $ sudo apt install mplayer
    
  8. mplayerコマンドでWAVファイルを再生し、Bluetoothデバイス(bt-receiverと別名定義)からオーディオ出力する。

    $ mplayer -ao alsa:device=bt-receiver /usr/share/sounds/alsa/Front_Center.wav
    

サイマルラジオを聴く

※参考:Raspberry Piをインターネットラジオ(radiko等)の再生環境にしたらとても快適だった!CUI操作編radikoやサイマルラジオを聞いてみよう!

  1. サイマルラジオのページを開く。
  2. 「放送を聴く」アイコンを右クリックし、プレイリストのURL(http://~/*.asx)を取得する。
  3. 取得したプレイリストのURLを-playlistオプションに記述し、次のコマンドを実行する。

    $ mplayer -ao alsa:device=bt-receiver -playlist http://www.simulradio.info/asx/fmpalulun.asx
    
  4. Bluetooth接続したスピーカーからサイマルラジオが流れる。

17
22
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
17
22