From 5c455ad1b57519c53fb26f6664b5eef9d25ee6c5 Mon Sep 17 00:00:00 2001 From: Abel Matser <33466359+abelmatser@users.noreply.github.com> Date: Mon, 1 Mar 2021 20:19:07 +0100 Subject: [PATCH 1/2] Add option for line-in Can be used for multiple setups, including edge cases where only a single channel is desired. Cpiped nor parec work in these cases. --- doc/player_setup.md | 40 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/doc/player_setup.md b/doc/player_setup.md index 90174af7e..aba496d17 100644 --- a/doc/player_setup.md +++ b/doc/player_setup.md @@ -224,6 +224,44 @@ source = process:///usr/bin/mpv?name=Webradio&sampleformat=48000:16:2¶ms=htt Audio captured from line-in can be redirected to the snapserver's pipe, e.g. by using: +#### Sox + +1. Install sox: `sudo apt update && sudo apt install sox` +2. Add fifo input to /etc/snapserver.conf: `stream = pipe:///tmp/snapfifo?name=soxfifo&sampleformat=$RATE:$BITS:$CHANNELS` +3. Test configuration with: `sox -V2 -q -r $RATE -b $BITS -c $CHANNELS -t alsa $DEVICE -t raw -L -r $RATE -b $BITS -c $CHANNELS - silence 1 0.2 0.05% -1 0.2 0.05% > /tmp/soxfifo + +Replace $RATE with sample rate (e.g. 44100), $DEVICE with alsa device - find with `arecord -l` (e.g. hw:1,0), $BITS with bits (e.g. 16), $CHANNELS with the amount of channels - for line in use 2, for your microphone jack use 1. The default would need you to put `stream = pipe:///tmp/snapfifo?name=soxfifo&sampleformat=44100:16:2` in /etc/snapserver.conf and run the following command: + +``` +sox -V2 -q -r 44100 -b 16 -c 2 -t alsa hw:1,0 -t raw -L -r 44100 -b 16 -c 2 - silence 1 0.2 0.05% -1 0.2 0.05% > /tmp/soxfifo +``` +When this works, create a service in /etc/systemd/system/sox.service: + +``` +[Unit] +Description=Sox stream from line in/microphone input to /tmp/soxfifo to be picked up by Snapcast +After=sound.target + +[Service] +Type=normal +User=$USER +ExecStart=/usr/bin/sox -V2 -q -r $RATE -b $BITS -c $CHANNELS -t alsa $DEVICE -t raw -L -r $RATE -b $BITS -c $CHANNELS - silence 1 0.2 0.05% -1 0.2 0.05% +Restart=always +StandardOutput=file:/tmp/soxfifo + +[Install] +WantedBy=multi-user.target +``` + +Replace $USER with the username whom can run the preceding command succesfully. Finally run: +``` +sudo systemctl daemon-reload +sudo service sox start +sudo service sox enable +sudo service sox status +``` +to start the service, automatically start it at boot and check if it is working. + #### cpiped [cpipe](https://github.com/b-fitzpatrick/cpiped) @@ -238,4 +276,4 @@ Use `--aout afile` and `--audiofile-file` to pipe VLC's audio output to the snap ```sh vlc --no-video --aout afile --audiofile-file /tmp/snapfifo -``` \ No newline at end of file +``` From 7d7baacc1986396cb1766169699231d2dd12b481 Mon Sep 17 00:00:00 2001 From: Abel Matser <33466359+abelmatser@users.noreply.github.com> Date: Sat, 8 May 2021 12:52:59 +0200 Subject: [PATCH 2/2] Update player_setup.md --- doc/player_setup.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/doc/player_setup.md b/doc/player_setup.md index aba496d17..e886735ba 100644 --- a/doc/player_setup.md +++ b/doc/player_setup.md @@ -256,9 +256,8 @@ WantedBy=multi-user.target Replace $USER with the username whom can run the preceding command succesfully. Finally run: ``` sudo systemctl daemon-reload -sudo service sox start -sudo service sox enable -sudo service sox status +sudo systemctl enable --now sox +sudo systemctl status sox ``` to start the service, automatically start it at boot and check if it is working.