ENOSUCHBLOG

Programming, philosophy, pedaling.


Introducing shaq, a CLI for Shazam

Jul 27, 2023     Tags: devblog, music, programming, python    


This is another tool announcement post, this time for shaq.

A demonstration animation of shaq, detecting a song.

As the demo implies, shaq does just one thing: it listens to an audio source and sends the results to Shazam for fingerprinting. If a match is found, it prints it.

As usual, you can install it from PyPI using pip or pipx:

1
2
3
4
5
pip install shaq
# or:
pipx install shaq

shaq --help

Usage

By default shaq listens to the system microphone (helpfully supplied through portaudio) and writes its findings as plain text, but you can tell it to detect from an arbitrary input instead:

1
2
3
4
5
6
7
8
# shaq analyzes the first 10 seconds by default
shaq --input mystery.mp3

# analyze a longer segment
shaq --input mystery.mp3 --duration 15

# anything with an audio track that ffmpeg can handle can be an input
shaq --input another-mystery.mp4

…as well as to emit JSON:

1
shaq --listen --duration 5 --json | jq '[.track.title, .track.subtitle]'

produces:

1
2
3
4
[
  "Mendacity",
  "Max Roach"
]

Under the hood, shaq is a relatively thin wrapper around PyAudio, pydub, and shazamio.

For the moment, shaq only supports fixed durations. Once I get bored again, I plan to add:

But why?

I am a compulsive scrobbler; I record almost everything I listen to, including phonograph records.

For records, I currently use Vinyl Scrobbler to scrobble records as I play them and it works very nicely (it even puts scrobbles in the future so that they end up mostly synchronized with the actual record!).

At the same time, it’s slightly more manual than I’d prefer: I’d like to be able to put a record on and have scrobbles come through automatically as each track starts. This is why I made shaq: my plan is to hook the (unused) headphones channel on my received into a Raspberry Pi, which will then run shaq either continuously or on a transition trigger (i.e., noise drop between tracks).

The Pi will then scrobble based on shaq’s results, satisfying my desire to be simultaneously too lazy to click a single button on my computer while also physically flipping big chunks of vinyl every 20 minutes.


Discussions: Mastodon Reddit