Sync lyrics to audio in FLAC files, locally.
Reads the LYRICS tag from a FLAC file — plain text or an existing
(possibly out-of-sync) LRC — and rewrites it with timestamps generated
straight from the audio. No cloud APIs, no LLM in the timing path: every
timestamp is grounded in an actual detected word and a real onset spike in
the waveform.
- Isolate vocals — demucs separates the track into vocal/instrumental stems so instrumental sections never get fed to the speech recognizer (the #1 cause of hallucinated lyrics).
- Transcribe — whisperx transcribes and force-aligns the isolated vocals, producing word-level timestamps.
- Align — the correct lyric lines (from the tag) are matched against
the ASR transcript with deterministic word-sequence matching
(
difflib). Only runs of 2+ consecutive matched words are trusted, so a single coincidental word match can't lock in a bogus timestamp. - Snap to onset — each matched timestamp is pulled back to the nearest real vocal onset detected via librosa, landing on the actual start of the word instead of somewhere in the middle of it.
- Write back — the FLAC's
LYRICStag is rewritten with the new LRC content. Each run parses whatever the tag currently holds, so you can hand-edit it (fix a misheard word, add a line that repeats in the song but was only written once) and the edit takes effect next run. No backup is kept — if a run goes wrong, delete the tag and re-fetch lyrics (e.g. from lrclib.net). - Sanity-check outliers — if alignment finds zero matches for every line (the given lyrics don't seem to be in the audio at all), that's run back through silero-vad as a second opinion. No vocal activity detected either → the tag is probably mislabeled; a warning is printed and the tag is left untouched rather than writing an all-interpolated, meaningless LRC.
- macOS/Linux with Python and
uvinstalled. - No manual dependency install needed —
lrc_fix.pycarries its dependencies as inline PEP 723 metadata;uvresolves and caches them on first run. - CPU works fine (slower); pass
--device cudaif you have a GPU.
curl -O https://raw.githubusercontent.com/<you>/lrc_fix/main/lrc_fix.py
chmod +x lrc_fix.pyOr just clone the repo.
# single file
./lrc_fix.py song.flac
# every .flac under a directory, recursively - only plain-text/un-timed lyrics
./lrc_fix.py ~/Music/some_album/
# also reprocess files that already have LRC timestamps
./lrc_fix.py ~/Music/some_album/ --all
# preview without writing the tag
./lrc_fix.py song.flac --dry-run
# force language instead of relying on auto-detect
./lrc_fix.py song.flac --language en
# scan a directory for files with no LYRICS tag at all: VAD-tag real
# instrumentals, log the rest as needing lyrics fetched
./lrc_fix.py ~/Music/some_album/ --find-missing-lyricsA file is skipped if it has no LYRICS tag, if the tag is empty after
stripping timestamps/header lines, or if it's just an instrumental
placeholder (Instrumental, [Instrumental], etc.) — no need to run
demucs/whisperx when there's no lyric text to align.
When path is a directory, files are found recursively (including
subdirectories). By default, only files whose LYRICS tag is not already
LRC-timestamped are fully realigned — pass --all to reprocess
already-timestamped files too. Already-LRC files aren't just skipped,
though: their [ar:]/[ti:]/[al:]/[length:] header lines still get
checked and refreshed against the FLAC's own tags (a metadata-only pass,
no demucs/whisperx; [re:] is left alone here — see below), while the
existing timestamped body — including a
manually added marker like [00:00.00](Spoken Intro) — is left completely
untouched. Files with no usable lyrics (missing tag, empty, or an
instrumental placeholder) are excluded from the count regardless of --all,
so the number reported up front matches what will actually run. This
filtering doesn't apply when path is a single file: naming a file directly
always processes it. The tool logs [i/N] <path> as each file starts.
| Flag | Default | Description |
|---|---|---|
--whisper-model |
medium |
whisperx/faster-whisper model size (tiny…large-v3) |
--language |
auto-detect | Force ASR language (ISO 639-1, e.g. en, de) |
--device |
cpu |
cpu or cuda |
--compute-type |
int8 |
faster-whisper compute type |
--jobs / -j |
min(4, cpu count) |
Parallel demucs jobs (each holds a model copy in memory) |
--dry-run |
off | Print the resulting LRC, don't write the tag |
--all |
off | Directory mode: also reprocess already-LRC-timestamped files |
--no-isolate-vocals |
off | Skip demucs separation, transcribe the full mix |
--no-snap-onsets |
off | Skip onset detection/snapping |
--no-vocal-check |
off | Skip the VAD fallback when alignment finds zero matches |
--find-missing-lyrics |
off | Scan for files with no LYRICS tag; VAD-tag instrumentals, log the rest |
--dump-words |
off | Print the raw ASR word/timestamp transcript (debugging) |
- First run downloads whisperx/demucs model weights from Hugging Face Hub,
and silero-vad (only used for the VAD fallback /
--find-missing-lyrics) from GitHub viatorch.hub— all cached (~/.cache/torch,~/.cache/huggingface) so later runs are fast to start. --whisper-model large*is rarely worth it here: since the correct lyrics text is already known, the alignment step only needs usable ASR output to match against, not maximally accurate transcription.- Standard LRC header lines (
[ar:...],[ti:...],[al:...]) in the tag are preserved as-is and never timestamped. Any of the three that's missing gets filled in from the file's ownARTIST/TITLE/ALBUMtags (when set). [re:https://github.com/koehntopp/lrc_fix](the LRC spec's "creator" tag) only gets (re)stamped when a run actually changes lyric content — a realignment, a completed instrumental marker, etc. A metadata-only refresh (correcting[ar:]/[ti:]/[al:]/[length:]) leaves any existing[re:]line exactly as it was. This also keeps files idempotent: a file whose metadata and lyrics are both already correct compares equal to its prior content and is left untouched entirely, rather than a stale[re:]value alone forcing a rewrite on every run.
MIT (or whatever you prefer — update this section).