-
-
Save Moonbase59/5e70279740a5b227c2106cff45abd706 to your computer and use it in GitHub Desktop.
spec - Quick-n-dirty spectrogram display for audio files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# spec - Copyright (c) 2024 Matthias C. Hormann | |
# 2024-03-26 | |
# Show spectrogram for an audio file, using ffmpeg's showspectrumpic | |
# Add this to the "Open with…" context menu of your file manager! | |
# define me | |
me=`basename "$0"` | |
version="0.2" | |
if [ -z "$1" ] ; then | |
exit 1; | |
fi | |
# Create temporary file names to use. | |
# kludge for MacOS: Mac variant first, then Linux: | |
TEMP=`mktemp -u -t ${me} 2>/dev/null || mktemp -u -t ${me}-XXXXXXXXXX` | |
TEMPIMG="${TEMP}.png" | |
TEMPTXT="${TEMP}.txt" | |
# Shell + ffmpeg quoting rules are a mess, and inconsistent, | |
# so better use a temporary text file for the info. | |
# Save the original file name to show in the spectrogram. | |
basename "$1" > "${TEMPTXT}" | |
# Note: showspectrumpic height MUST be a power of 2! | |
ffmpeg -v quiet -y -i "$1" -filter_complex showspectrumpic=s=1024x512:stop=22000,drawtext="expansion=none:textfile='${TEMPTXT}':x=(w-tw)/2:y=16:fontcolor='white':fontsize=20" "$TEMPIMG" | |
exitcode=$? | |
if [ $exitcode -ne 0 ] ; then | |
rm "$TEMPTXT" | |
exit $exitcode | |
fi | |
# Open in your default PNG image file viewer. | |
# Using a subshell here so we can wait until closed, before removing the temp file | |
# Macs don’t have `xdg-open`, so use `open` instead. Requires correct file extension. | |
dummy=$(open "$TEMPIMG") | |
rm "$TEMPIMG" "$TEMPTXT" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
spec
Quick-n-dirty spectrogram display for audio files, using ffmpeg.
I did this because I missed good old
spek
so much… It’s been on a long hiatus and not available in Ubuntu & Linux Mint for a while, but it’ll come back (already in Debian Bookworm, I reckon).Copy this to a location in your path (
~/bin
,~/.local/bin
,/usr/local/bin
come to mind),chmod +x
it and you can quickly watch an audiofile’s spectrogram from the commandline:It will open in your default PNG file viewer:
You can also add this command as an Open With… context menu entry in your favourite file manager, for more ease of use.