Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Analyze long audio files with audd.io.
#!/bin/bash -ex
mkdir -p audd
if (( $# < 2 )); then
echo "Please supply two arguments, the input file and the timestamp (HH:MM:SS)."
exit 1
fi
fn=$1
pos=$(date -d "1970-01-01 $2" -u +%s)
# 11 requests per day with test token:
audd_api_token=test
echo "fn: $fn"
echo "pos: $pos"
pos_padded=$(printf "%05d" "$pos")
if [[ ! -f "audd/$pos_padded.mp3" ]]; then
ffmpeg -hide_banner -i "$fn" -ss "$pos" -t 10 "audd/$pos_padded.mp3"
fi
if [[ -f "audd/$pos_padded.json" ]]; then
exit
fi
curl -fsS https://api.audd.io/ \
-F file=@audd/$pos_padded.mp3 \
-F api_token=$audd_api_token \
-o audd/$pos_padded.json
if cat "audd/$pos_padded.json" | jq -e '.error?' > /dev/null; then
cat "audd/$pos_padded.json" | jq
rm "audd/$pos_padded.json"
exit
fi
cat "audd/$pos_padded.json" | jq -Mr '.result'
#!/bin/bash -e
shopt -s extglob
for fn in audd/*.json; do
basename=$(echo "$fn" | cut -d/ -f2 | cut -d. -f1)
pos="${basename##+(0)}"
timestamp=$(date -d@$pos -u +%-H:%M:%S)
artist=$(jq -Mr '.result.artist' < "$fn")
title=$(jq -Mr '.result.title' < "$fn")
echo "$timestamp $artist - $title"
done
#!/bin/bash -ex
mkdir -p audd
if (( $# < 1 )); then
echo "Please supply the filename."
exit 1
fi
# 11 requests per day with test token:
audd_api_token=test
duration=$(ffprobe -hide_banner -v error -select_streams a:0 -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 "$1" | cut -d. -f1)
for pos in $(seq 30 300 $duration); do
pos_padded=$(printf "%05d" "$pos")
if [[ ! -f "audd/$pos_padded.mp3" ]]; then
ffmpeg -hide_banner -i "$1" -ss "$pos" -t 20 "audd/$pos_padded.mp3"
fi
if [[ ! -f "audd/$pos_padded.json" ]]; then
curl -fsS https://api.audd.io/ \
-F file=@audd/$pos_padded.mp3 \
-F api_token=$audd_api_token \
-o audd/$pos_padded.json
if cat "audd/$pos_padded.json" | jq -e '.error?' > /dev/null; then
cat "audd/$pos_padded.json" | jq
rm "audd/$pos_padded.json"
exit
else
cat "audd/$pos_padded.json" | jq '.result'
fi
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment