Files
illogical-impulse/dots/.config/quickshell/ii/scripts/musicRecognition/recognize-music.sh
T
Aman 0725edd35d refactor(musicRecognition): replace parec/ffmpeg pipeline with songrec listen fix:#3057
Use `songrec listen --audio-device` instead of manually capturing audio
with parec, converting with ffmpeg, and passing to audio-file-to-recognized-song.
Drops temp file handling and simplifies the recognition loop.
2026-03-01 15:46:02 +05:30

49 lines
1.1 KiB
Bash
Executable File

#!/bin/bash
INTERVAL=10
TOTAL_DURATION=30
SOURCE_TYPE="monitor" # monitor | input
while getopts "i:t:s:" opt; do
case $opt in
i) INTERVAL=$OPTARG ;;
t) TOTAL_DURATION=$OPTARG ;;
s) SOURCE_TYPE=$OPTARG ;;
*) exit 1 ;;
esac
done
if ! command -v songrec >/dev/null 2>&1; then
exit 1
fi
if [ "$SOURCE_TYPE" = "monitor" ]; then
AUDIO_DEVICE=$(pactl get-default-sink).monitor
elif [ "$SOURCE_TYPE" = "input" ]; then
AUDIO_DEVICE=$(pactl info | grep "Default Source:" | awk '{print $3}' || true)
else
echo "Invalid source type"
exit 1
fi
if [ -z "$AUDIO_DEVICE" ] || ! pactl list short sources | grep -q "$AUDIO_DEVICE"; then
exit 1
fi
cleanup() {
kill "$SONGREC_PID" 2>/dev/null || true
}
trap cleanup EXIT
songrec listen --audio-device "$AUDIO_DEVICE" --request-interval "$INTERVAL" --json --disable-mpris | while IFS= read -r line; do
if echo "$line" | grep -q '"matches": \['; then
echo "$line"
kill "$SONGREC_PID" 2>/dev/null || true
exit 0
fi
done &
SONGREC_PID=$!
sleep "$TOTAL_DURATION"
exit 0