I always wanted lyrics floating over my screen while I work, so I built it
I love music. It's on all day while I work: a playlist in the background, code in front of me. And for a long time I've wished for one thing: the lyrics, right there on my screen, on top of whatever I'm doing.
Not in another window I have to switch to. Not in a lyrics tab buried behind my editor. Just floating over my work, word by word, in time with the song, so I can sing along without stopping.
So I finally built it. mondegreen is a free, open-source lyrics overlay for Windows. Play a song in Spotify or YouTube, and the lyrics float on top of every window. Every word lights up the moment it's sung, and everything moves on the beat, so you feel the song instead of just reading it. And when I only want to listen, Ctrl Alt F turns it into a full-screen lyrics visualizer.
(The name: a "mondegreen" is a misheard lyric, like "'scuse me while I kiss this guy." With the real words on screen, those get fixed too.)
nirajkhetre / mondegreen - Free synced lyrics overlay for Spotify on Windows: word-by-word karaoke lyrics on top of your screen, moving with the beat, plus a full-screen lyrics visualizer.
mondegreen: synced lyrics overlay for Spotify on Windows. Word-by-word lyrics that sing along on top of your screen while you work, move with the beat of the song, and turn into a full-screen music visualizer when you just want to listen. Website ยท Wiki ยท Download ยท Report a bug.
A mondegreen is a misheard lyric: "'Scuse me while I kiss this guy." This app is the fix. It shows you the real words, exactly when they're sung.
Why mondegreen
- Synced to the word, not just the line. Every word lights up the moment it's sung, from word-timed karaoke lyrics, so you never lose your place.
- It feels the beat. A beat tracker listens to your speakers and locks onto the tempo, so the lyrics bounce, slam and glow on the beat instead of reacting late.
- Out of your way. A click-through overlay that floats above every window, hides aโฆ View on GitHub
Getting lyrics on screen was the easy part. Getting them to land exactly when they're sung, and to move on the beat rather than after it, took most of the work. Here's how each piece works.
1. Knowing exactly where the song is
My first version polled the player's position and drifted. Lyrics were a few hundred milliseconds late, then early, then late. Windows already knows what's playing: the Global System Media Transport Controls session (the media flyout you see when you press a volume key). No Spotify login, no API key, no Premium.
I read it from a tiny PowerShell script that prints a JSON line whenever something changes:
$t = $s.GetTimelineProperties()
$o = [ordered]@{
app = $s.SourceAppUserModelId;
title = $meta.Title;
artist = $meta.Artist
pos = [int]$t.Position.TotalMilliseconds;
dur = [int]$t.EndTime.TotalMilliseconds
at = $t.LastUpdatedTime.ToUnixTimeMilliseconds()
playing = ($s.GetPlaybackInfo().PlaybackStatus.ToString() -eq 'Playing')
}
The key is LastUpdatedTime. Each position report carries the player's own timestamp for that position. So between reports I don't guess: the position right now is pos + (now โ at).
// the player stamps each position report with its own clock (np.at), so between reports we extrapolate exactly;
// small disagreements glide in instead of jumping, seeks snap
function songPos(now) {
const np = L.np, target = np.playing ? np.pos + (Date.now() - np.at) : np.pos || 0
const est = shown + (np.playing ? now - shownAt : 0)
shown = Math.abs(target - est) > 250 ? target : est + (target - est) * 0.06
shownAt = now
return shown - (L.S.delay || 0) + (L.S.offsets?.[L.key] || 0)
}
That one change fixed the drift. On real Spotify songs, vocals came in within 20-200 ms of the line starts. For the songs where a lyric file is off, there's a tap-to-sync shortcut that remembers the offset per song.
One thing I tried and rejected: a native SMTC module for Node. Its lastUpdatedTime came back as the query time, not the player's stamp, which breaks exactly this trick.
2. Lighting up every word
Most synced lyrics are timed per line. I wanted every word. Kugou's KRC format times every syllable. The files are base64, with a 4-byte header, XOR'd with a fixed 16-byte key, then zlib-compressed. Decoding is four lines in Node:
const raw = Buffer.from(d.content, 'base64').subarray(4)
for (let i = 0; i < raw.length; i++) raw[i] ^= KRC_KEY[i % 16]
const lines = parseKrc(zlib.inflateSync(raw).toString('utf8'), c)
return lines.length > 3 ? { source: 'Kugou', kind: 'word', lines } : null
When Kugou has nothing, LRCLIB is the fallback, with line timing; I spread the words across each line by syllable count so they still light up one by one.
The rule that saved me from the most wrong lyrics: both sources must match the track's length (within 3-4 seconds). A live version or an extended mix never gets studio timing. YouTube titles like Artist - Song (Official Video) [4K] get cleaned up before searching, and everything is cached on disk, so a song you've played before shows its lyrics instantly, even offline.
3. Hearing the beat before it lands
Reacting to the beat isn't enough. By the time you detect a kick, it's already over, so anything you animate is late. I wanted the page to know when the next beat lands. Everything runs in an AudioWorklet on the audio thread, fed by system-audio loopback:
Onset envelope. Split the audio into low, mid and high bands and keep the rises in energy (spectral flux), about 94 frames a second.
Tempo. Autocorrelate the last 8 seconds of that envelope. Peaks are candidate beat periods; a soft preference for ~120 BPM stops it from picking half or double the real tempo:
const bpm = 60 * fps / L, s = r[L] * Math.exp(-0.5 * (Math.log2(bpm / 120) / 0.8) ** 2)
Hold the grid. The hardest bug: on some songs it kept flipping between half and double the real tempo, and the whole scene jittered. Half, double and 2:3 tempos are the same groove heard differently, so they never reset the grid. A genuinely new tempo has to win four checks in a row:
else if (![0.5, 2/3, 1.5, 2].some(h => Math.abs(ratio / h - 1) < 0.045) && candConf > 0.35) {
if (this.streak && Math.abs(cand / this.challenger - 1) < 0.04) this.streak++
else { this.challenger = cand; this.streak = 1 }
if (this.streak >= 4) { this.period = cand; this.anchor = 0; this.streak = 0 }
}
Phase lock. Find the offset where the last ~4 seconds of onsets pile up, then nudge the grid halfway toward it on each check, like a phase-locked loop with a gain of 0.5. With that, the grid error on real songs dropped to 0-9 ms. Animations are scheduled for the predicted beat, so they land on it. When there's no steady tempo (intros, ballads), confidence drops and the visuals react to hits instead.
4. What a 144 Hz screen did to my CPU
The first build used CSS animations everywhere. On my laptop's 144 Hz screen, every one of them ran 144 times a second, inside a transparent always-on-top window, which costs a full copy per frame. The overlay sat at up to 127% of a core; the settings window, with its live previews, hit 275%.
The fix: no CSS animations or filters on anything that moves. One loop drives all motion by setting a few CSS variables per word, capped at 60 fps (or 30), sleeping with setTimeout and only then asking for a frame:
// sleep until the next frame is due, then ask for a frame (asking every vsync would wake us 144 times a second)
if (f.paused) timer = setTimeout(() => loop(performance.now()), 100)
else timer = setTimeout(() => { timer = 0; raf = requestAnimationFrame(loop) }, Math.max(0, FRAME - (performance.now() - drawn) - 6))
The overlay dropped to 40-70% of one core while animating, about 6% hidden. Settings went from 275% to about 85%, mostly by letting preview cards animate only under the mouse.
5. Twelve looks and ten full-screen scenes
Since every look reads the same word timings and beat clock, adding looks became fun: a notch that stretches to each line, a split-flap departures board, a ransom-note zine, words that fall and bounce on the beat. There are twelve.
Listen mode (Ctrl Alt F) runs one WebGL2 fragment shader per scene, driven by a monotonic beat counter instead of time, so lasers jump on beats and suns step down per beat. Each scene is coloured from the album art.
My favourite, Late Night Texts, has no image files at all. It's an SVG drawn in code to look like a sketchbook: feTurbulence plus feDisplacementMap wobble every ink line, a noise mask makes them grainy like pencil, and the watercolour washes are blurred, displaced fills with mix-blend-mode: multiply.
<filter id="sk-ink">
<feTurbulence type="fractalNoise" baseFrequency=".03" numOctaves="2" seed="3" result="n" />
<feDisplacementMap in="SourceGraphic" in2="n" scale="3.4" xChannelSelector="R" yChannelSelector="G" />
</filter>
The guy never moves; the room does. Sound lines leave his headphones on each beat, and the lyrics arrive as a chat on his monitor. The effect lines re-roll their wobble every few frames, which reads as hand-drawn "line boil".
6. Shipping a Windows exe
electron-builder makes the installer and a portable exe. One gotcha to plan for: PowerShell can't read files inside the app.asar archive, so the now-playing script would fail in the packaged app. The fix is to ship the scripts unpacked and point at that folder:
"asarUnpack": ["*.ps1"]
const scripts = __dirname.replace(/app\.asar$/, 'app.asar.unpacked')
What I'd do next
Code-sign the exe, so SmartScreen stops warning on first run. Show translation lines (KRC files already carry them). Calibrate Bluetooth latency automatically from the loopback audio.
Try it
It's free and MIT-licensed. Windows 10 or 11, installer or portable exe:
Download: https://github.com/nirajkhetre/mondegreen/releases/latest
Wiki (deep dives): https://github.com/nirajkhetre/mondegreen/wiki
Website: https://nirajkhetre.github.io/mondegreen/
If you work with music on too, I'd love to know what you'd want floating on your screen. Tell me in the comments.
Comments
No comments yet. Start the discussion.