Yado_tech

旅館+ITとはなんぞ

Raspberry PiでMultiroom Audio

f:id:devilmakelie:20200924234520p:plain


Spotifyを家中で聞きたい・・家中を音楽で満たしたい・・・そう思ったことはありませんか?私はあります。

でもケーブルを家中に敷設するのは見た目も悪いし・・・そう思ったことはありませんか?私はあります。

てことでRaspberry Piを利用してMultiRoom Audioをしてみました。

全体的なイメージはこんな感じです。

f:id:devilmakelie:20200924235840p:plain


順を追って行きます。

サーバー編

Raspotify のインストール

かなり簡単で、ワンライナーで行けます。

 curl -sL https://dtcooper.github.io/raspotify/install.sh | sh 

Snapcast Serverのインストール


バージョンなどはReleasesのページで適宜最新にして読み替えてください。

wget https://github.com/badaix/snapcast/releases/download/v0.21.0/snapserver_0.21.0-1_armhf.deb
sudo dpkg -i snapserver_0.21.0-1_armhf.deb

Raspotifyの設定

/etc/default/raspotify を編集します。

sudo nano /etc/default/raspotify 
# /etc/default/raspotify -- Arguments/configuration for librespot

# Device name on Spotify Connect
DEVICE_NAME="<好きな名前(日本語可)>"

# Bitrate, one of 96 (low quality), 160 (default quality), or 320 (high quality)
BITRATE="320"

# Additional command line arguments for librespot can be set below.
# See `librespot -h` for more info. Make sure whatever arguments you specify
# aren't already covered by other variables in this file. (See the daemon's
# config at `/lib/systemd/system/raspotify.service` for more technical details.)
#
# To make your device visible on Spotify Connect across the Internet add your
# username and password which can be set via "Set device password", on your
# account settings, use `--username` and `--password`.
#
# To choose a different output device (ie a USB audio dongle or HDMI audio out),
# use `--device` with something like `--device hw:0,1`. Your mileage may vary.
#
OPTIONS="--username <SPOTIFYのユーザーネーム> --password <SPOTIFYのパスワード> --zeroconf-port 65444"

# Uncomment to use a cache for downloaded audio files. Cache is disabled by
# default. It's best to leave this as-is if you want to use it, since
# permissions are properly set on the directory `/var/cache/raspotify'.
#CACHE_ARGS="--cache /var/cache/raspotify"

# By default, the volume normalization is enabled, add alternative volume
# arguments here if you'd like, but these should be fine.
#VOLUME_ARGS="--enable-volume-normalisation --linear-volume --initial-volume=100"

# Backend could be set to pipe here, but it's for very advanced use cases of
# librespot, so you shouldn't need to change this under normal circumstances.
BACKEND_ARGS="--backend pipe --device /tmp/snapfifo"

必要なのはDEVICE NAME、OPTIONS、BACKEND_ARGSの3つ
OPTIONSには開放するポート番号を--zeroconf-port以降に、
BACKEND_ARGSにはパイプを指定してあげましょう。

Snapcast Serverの設定

/etc/default/snapserver を編集しますが、今回は特に必要ありません。

 sudo nano /etc/default/snapserver 

次にサンプルレートを変更しましょう

サンプルレートは`/etc/snapserver.conf`で変更できます。
[stream]セクションに置くみたいです。

source = pipe:///tmp/snapfifo?name=default
sampleformat = 44100:16:2

それぞれ設定した後は再読込しておきましょう。

sudo service snapserver restart 
sudo service raspotify restart

ufwファイアウォール)の設定

ip-tablesのラッパー。とっても簡単なのでサクッとインストールしておきましょう。

sudo apt-get install ufw
sudo ufw allow 22 #SSH用のポートを開けておく
sudo ufw allow 1704 #snapserver用のポート①
sudo ufw allow 1705 #snapserver用のポート②
sudo ufw allow 1780 #snapeserver web用のポート
sudo ufw allow 65444 #raspotify用のポート

クライアント側のラズパイの設定

snapclientのインストール

wget https://github.com/badaix/snapcast/releases/download/v0.21.0/snapclient_0.21.0-1_armhf.deb
sudo dpkg -i snapclient_0.21.0-1_armhf.deb

Snapcast Clientの設定

/etc/default/snapclientの設定

sudo nano /etc/default/snapclient
START_SNAPCLIENT=true
SNAPCLIENT_OPTS="--host "

hostにはサーバーのIPアドレスを指定してください。

Snapclientのリスタート

sudo service snapclient restart

Tips

コマンドラインでのボリュームの変更

alsamixerを使用します。

alsamixer

nano(ラズパイ用のコマンドラインエディタ)を終了する方法

CTRL+Xで終了し、Yを押して保存します。

WEB上で音量を調整したいとき

snapserverのIPアドレス:1780でWEBにもアクセスできます。

f:id:devilmakelie:20200925161721p:plain




あとは適当なスマホSpotifyを実行し、ConnectでSnapcastを選べばMultiroom Audioが出来ます。

これで音楽に包まれた生活ができますね。最高!