From 9d0cb08792d766dd94d91a580b516aa83014c656 Mon Sep 17 00:00:00 2001 From: Samuel ORTION Date: Mon, 22 Aug 2022 05:46:59 +0200 Subject: [PATCH] install: Adding `loginctl enable-linger` for user recording using pulseaudio --- INSTALL.md | 16 +++++++++++----- daemon/birdnet_recording.sh | 12 +++++++++--- daemon/systemd/templates/birdnet_miner.timer | 2 +- install.sh | 6 ++++-- 4 files changed, 25 insertions(+), 11 deletions(-) diff --git a/INSTALL.md b/INSTALL.md index dfee2ff..0b3a110 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -79,17 +79,23 @@ sudo systemctl enable --now birdnet_recording.service birdnet_analyzis.service b #### Check if services are working ```bash -# Sercices status -sudo systemctl status birdnet_recording.service birdnet_analyzis.service -# Timers status -sudo systemctl status birdnet_miner.timer +# Sercices and timers status +sudo systemctl status birdnet_\* ``` ```bash # BirdNET-stream logs -sudo journalctl -feu {birdnet_recording,birdnet_analyzis}.service +sudo journalctl -feu birdnet_\* ``` +#### Enable `loginctl-linger` for the user that runs the servuces + +Running: +```bash +loginctl enable-linger +``` +This allows to use `/run/user/1000/pulse` to record audio using PulseAudio in birdnet_recording.sh. + ## Setup BirdNET-stream symfony webapp ### Install php 8.1 diff --git a/daemon/birdnet_recording.sh b/daemon/birdnet_recording.sh index 7b002b9..1b97d64 100755 --- a/daemon/birdnet_recording.sh +++ b/daemon/birdnet_recording.sh @@ -3,6 +3,7 @@ DEBUG=${DEBUG:-1} export PULSE_RUNTIME_PATH="/run/user/$(id -u)/pulse/" +FFMPEG_OPTIONS="-nostdin -hide_banner -loglevel error -nostats -vn -acodec pcm_s16le -ac 1 -ar 48000" debug() { if [ $DEBUG -eq 1 ]; then @@ -27,20 +28,25 @@ record_loop() { done } -FFMPEG_OPTIONS="-nostdin -hide_banner -loglevel error -nostats -vn -acodec pcm_s16le -ac 1 -ar 48000 " record_stream() { local STREAM=$1 local DURATION=$2 local debug "Recording from $STREAM for $DURATION seconds" - ffmpeg $FFMPEG_OPTIONS -f -i ${DEVICE} -t ${DURATION} file:${CHUNK_FOLDER}/in/birdnet_$(date "+%Y%m%d_%H%M%S").wav + ffmpeg $FFMPEG_OPTIONS -i ${STREAM} -t ${DURATION} file:${CHUNK_FOLDER}/in/birdnet_$(date "+%Y%m%d_%H%M%S").wav } record_device() { DEVICE=$1 DURATION=$2 debug "Recording from $DEVICE for $DURATION seconds" - ffmpeg $FFMPEG_OPTIONS -f pulse -i ${DEVICE} -t ${DURATION} -af "volume=$RECORDING_AMPLIFY" file:${CHUNK_FOLDER}/in/birdnet_$(date "+%Y%m%d_%H%M%S").wav + local ffmpeg_input + if [[ "$AUDIO_USE_PULSE" = "true" ]]; then + ffmpeg_input="-f pulse -i ${DEVICE}" + else + ffmpeg_input="-f alsa -i ${DEVICE}" + fi + ffmpeg $FFMPEG_OPTIONS $ffmpeg_input -t ${DURATION} -af "volume=$RECORDING_AMPLIFY" file:${CHUNK_FOLDER}/in/birdnet_$(date "+%Y%m%d_%H%M%S").wav } config_filepath="./config/birdnet.conf" diff --git a/daemon/systemd/templates/birdnet_miner.timer b/daemon/systemd/templates/birdnet_miner.timer index 2cf267e..931c73f 100644 --- a/daemon/systemd/templates/birdnet_miner.timer +++ b/daemon/systemd/templates/birdnet_miner.timer @@ -6,4 +6,4 @@ OnCalendar=*:0/15 Unit=birdnet_miner.service [Install] -WantedBy=basic.target \ No newline at end of file +WantedBy=timers.target \ No newline at end of file diff --git a/install.sh b/install.sh index db13113..b60ccc0 100755 --- a/install.sh +++ b/install.sh @@ -5,7 +5,7 @@ set -e DEBUG=${DEBUG:-0} -REQUIREMENTS="git wget ffmpeg python3 python3-pip python3-dev python3-venv g{,un}zip sqlite3" +REQUIREMENTS="git wget ffmpeg python3 python3-pip python3-dev python3-venv gzip sqlite3" REPOSITORY=${REPOSITORY:-https://github.com/UncleSamulus/BirdNET-stream.git} BRANCH=${BRANCH:-main} WORKDIR="$(pwd)/BirdNET-stream" @@ -48,7 +48,7 @@ install_birdnetstream() { # Clone BirdNET-stream cd "$WORKDIR" debug "Cloning BirdNET-stream from $REPOSITORY" - git clone -b "$BRANCH"--recurse-submodules "$REPOSITORY" . + git clone -b "$BRANCH" --recurse-submodules "$REPOSITORY" . debug "Creating python3 virtual environment $PYTHON_VENV" python3 -m venv $PYTHON_VENV debug "Activating $PYTHON_VENV" @@ -219,6 +219,8 @@ main() { install_web_interface setup_http_server install_config + debug "Run loginctl enable-linger for $USER" + loginctl enable-linger update_permissions debug "Installation done" }