LiveLyrics reads media metadata directly from the Windows operating system using theDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/x-eon-max/LiveLyrics/llms.txt
Use this file to discover all available pages before exploring further.
winsdk Python bindings for the GlobalSystemMediaTransportControls (SMTC) API. On every loop iteration it retrieves two things: the track’s identity (title and artist) to know which song is playing, and the current playback position to know exactly where in that song the listener is.
Session Retrieval
The entry point for all media queries isMediaManager.request_async(), which returns a snapshot of every active SMTC session currently registered with Windows. Calling get_current_session() on that snapshot returns the OS-level “current” session — typically the most recently active audio source.
get_current_session() returns None, and the main loop skips that iteration gracefully.
Track Metadata
Once a session is obtained,try_get_media_properties_async() fetches the track’s metadata — title, artist, album art, and more — directly from the playing application. LiveLyrics extracts only the fields it needs:
title and artist — which are then passed to the lyrics-fetching pipeline and used to construct the fallback status string.
Playback Position and Extrapolation
Knowing the track is not enough — LiveLyrics also needs to know where in the track the listener currently is, down to the millisecond, so it can select the correct lyric line.get_timeline_properties() provides two key values:
position— the playback position at the moment the OS last updated it. This may be atimedeltaobject or a raw tick value (100-nanosecond units), so LiveLyrics handles both.last_updated_time— the UTCdatetimeat which that position snapshot was taken.
get_playback_info() provides the playback_status integer. A value of 4 means the track is actively playing.
Because the Windows SMTC API may return position either as a timedelta object (which exposes .total_seconds()) or as a raw integer count of 100-nanosecond ticks, get_position_seconds normalises the value before doing anything else:
4, LiveLyrics calculates how much wall-clock time has passed since last_updated_time and adds it to the reported position:
The Windows SMTC API updates the timeline position only periodically — not continuously. Without this extrapolation step, the reported position would often be several hundred milliseconds behind the actual audio playback, causing the wrong lyric line to be displayed. By computing the elapsed wall-clock time since the last OS update and adding it to the base position, LiveLyrics stays tightly synchronized with what the listener is actually hearing.
Track Change Detection
main() tracks the currently playing song using a last_track_key tuple:
(title, artist) pair changes, LiveLyrics treats it as a new song: it triggers a fresh lyrics fetch (or cache lookup), resets the last_line pointer so the first matching lyric is sent to Discord immediately, and starts position tracking from scratch.
The Windows SMTC API is application-agnostic — it captures audio metadata from any application that registers with it, including Spotify, YouTube (in a browser), Windows Media Player, VLC, and most modern media players. LiveLyrics works with all of them without any app-specific configuration.