#!/usr/bin/env bash # Renders a waveform + spectrogram image for a clip of an audio file, so a # suspicious cut point can be inspected directly rather than only reasoned # about from correlation numbers or transcript text. A dense, continuous # band is speech or music; a flat/quiet stretch is silence; an abrupt # change in texture is usually where one kind of content ends and another # begins (e.g. the station's intro bed stopping and a host's raw recording # starting). # # Usage: # tools/visualize_clip.sh [start_seconds] [duration_seconds] [output.png] # # Examples: # tools/visualize_clip.sh cache/audio/hpr4775.opus # tools/visualize_clip.sh cache/audio/hpr4775.opus 0 55 # tools/visualize_clip.sh cache/audio/hpr3700.mp3 880 90 /tmp/hpr3700_outro.png # # Requires only ffmpeg (already a dependency of this repo); no Python, no # extra packages. set -euo pipefail if [ "$#" -lt 1 ]; then echo "Usage: $0 [start_seconds] [duration_seconds] [output.png]" >&2 exit 1 fi audio_file="$1" start="${2:-0}" duration="${3:-60}" default_out="$(basename "${audio_file%.*}")_${start}-$((start + duration))s.png" out="${4:-$default_out}" ffmpeg -v error -y -i "$audio_file" -ss "$start" -t "$duration" -ar 16000 -ac 1 \ -filter_complex \ "[0:a]showwavespic=s=1200x200:colors=white[wave];[0:a]showspectrumpic=s=1200x300:legend=0[spec];[wave][spec]vstack" \ -frames:v 1 "$out" echo "Wrote $out (waveform on top, spectrogram below, covering ${start}s-$((start + duration))s of $audio_file)"