https://blog.yossarian.net/2023/07/27/Introducing-shaq-a-CLI-for-shazam ENOSUCHBLOG Programming, philosophy, pedaling. * Home * Tags * Series * Favorites * Archive * Main Site --------------------------------------------------------------------- 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 pip install shaq 2 # or: 3 pipx install shaq 4 5 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 # shaq analyzes the first 10 seconds by default 2 shaq --input mystery.mp3 3 4 # analyze a longer segment 5 shaq --input mystery.mp3 --duration 15 6 7 # anything with an audio track that ffmpeg can handle can be an input 8 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 "Mendacity", 3 "Max Roach" 4 ] 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: * Support for "rolling" detections, i.e. "listen until you get a match"; * Support for timeranges in file inputs, i.e., "15 seconds starting at 00:12:13". 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 --------------------------------------------------------------------- Previously Newer