Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion scripts/musicRecognition/recognize-music.sh
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ trap cleanup EXIT

/usr/bin/mkdir -p "$TMP_PATH"
/usr/bin/parec --device="$MONITOR_SOURCE" --format=s16le --rate=44100 --channels=2 > "$TMP_RAW" &
PAREC_PID=$!
START_TIME=$(/usr/bin/date +%s)

while true; do
Expand All @@ -53,11 +54,17 @@ while true; do
if (( ELAPSED >= TOTAL_DURATION )); then
exit 0
fi

# stop immediately if parec dont find the correct audio source
if ! kill -0 $PAREC_PID 2>/dev/null; then
exit 1
fi

/usr/bin/ffmpeg -f s16le -ar 44100 -ac 2 -i "$TMP_RAW" -acodec libmp3lame -y -hide_banner -loglevel error "$TMP_MP3" 2>/dev/null
RESULT=$(/usr/bin/songrec recognize -j "$TMP_MP3" 2>/dev/null || true)

if echo "$RESULT" | /usr/bin/grep -q '"matches": \[' && [ ${#RESULT} -gt $MIN_VALID_RESULT_LENGTH ]; then
# better if shazam api change
if echo "$RESULT" | /usr/bin/grep -q '"track"'; then
echo "$RESULT"
exit 0
fi
Expand Down