npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

timestamped-lyrics

v1.0.3

Published

Simple Package to fetch and display timestamped lyrics for a given song.

Readme

Timestamped Lyrics

A TypeScript package for fetching and displaying timestamped lyrics for songs. This library provides an easy way to search for lyrics and retrieve synced lyrics with timestamps, perfect for karaoke applications or music players.

Features

  • 🎵 Search for lyrics by song title and artist name
  • ⏱️ Timestamped lyrics with precise timing information
  • 🎯 Duration-based matching to find the most accurate lyrics
  • 🔄 Synced lyrics parsing with start/end times for each line
  • 📦 TypeScript support with full type definitions
  • 🎤 Karaoke-ready format with properly parsed lyric lines

Installation

npm install timestamped-lyrics

Quick Start

import { LyricalClient } from 'timestamped-lyrics';

const client = new LyricalClient();

// Search for lyrics
const searchResults = await client.querySongLyrics('Shape of You', 'Ed Sheeran');
console.log(searchResults);

// Get the best matching lyrics (with optional duration filtering)
const lyrics = await client.getLyrics('Shape of You', 'Ed Sheeran', {
  duration: 263, // Optional: duration in seconds for better matching
  syncedOnly: true // Optional: only return results with synced lyrics
});
console.log(lyrics);

// Get parsed lyric lines with timestamps
const lyricLines = await client.getLyricLines('Shape of You', 'Ed Sheeran');
lyricLines.forEach(line => {
  console.log(`${line.start}s - ${line.end}s: ${line.text}`);
});

API Reference

LyricalClient

The main client class for interacting with the lyrics API.

Constructor

const client = new LyricalClient(options?: LyricalClientOptions);

Methods

querySongLyrics(song: string, artist: string, options?: QuerySongOptions): Promise<LyricSearchResult[]>

Search for lyrics and return up to 20 results.

Parameters:

  • song - The title of the song
  • artist - The name of the artist
  • options - Optional query parameters

Options:

  • syncedOnly?: boolean - If true, only returns results with synced lyrics (default: false)
getLyrics(song: string, artist: string, options?: GetLyricsOptions): Promise<LyricSearchResult>

Get the closest matching lyrics for a song.

Parameters:

  • song - The title of the song
  • artist - The name of the artist
  • options - Optional parameters for lyrics retrieval

Options:

  • duration?: number - Optional duration in seconds for better matching
  • syncedOnly?: boolean - If true, only returns results with synced lyrics (default: false)
getLyricLines(song: string, artist: string, options?: GetLyricsOptions): Promise<LyricLine[]>

Get parsed synced lyric lines with timestamps.

Parameters:

  • song - The title of the song
  • artist - The name of the artist
  • options - Optional parameters (syncedOnly defaults to true for this method)

Returns: Array of LyricLine objects with start time, end time, and text.

static parseSyncedLyrics(lyrics: LyricSearchResult): LyricLine[]

Static method to parse synced lyrics from a LyricSearchResult object.

Types

LyricSearchResult

type LyricSearchResult = {
  id: number;
  name: string;
  trackName: string;
  artistName: string;
  albumName: string;
  duration: number; // in seconds
  instrumental: boolean;
  plainLyrics: string; // unformatted lyrics
  syncedLyrics: string; // formatted lyrics with timestamps
};

LyricLine

type LyricLine = {
  start: number; // start time in seconds
  end: number;   // end time in seconds
  text: string;  // the lyric text
};

Examples

Basic Usage

import { LyricalClient } from 'timestamped-lyrics';

const client = new LyricalClient();

try {
  // Search for multiple results
  const results = await client.querySongLyrics('Bohemian Rhapsody', 'Queen');
  console.log(`Found ${results.length} results`);

  // Get the best match
  const lyrics = await client.getLyrics('Bohemian Rhapsody', 'Queen');
  console.log(`Song: ${lyrics.trackName} by ${lyrics.artistName}`);
  console.log(`Duration: ${lyrics.duration} seconds`);
  
  if (lyrics.syncedLyrics) {
    console.log('Synced lyrics available!');
  }
} catch (error) {
  console.error('Error fetching lyrics:', error.message);
}

Karaoke Application

import { LyricalClient } from 'timestamped-lyrics';

const client = new LyricalClient();

async function createKaraokeDisplay(song: string, artist: string) {
  try {
    const lyricLines = await client.getLyricLines(song, artist);
    
    // Display lyrics with timing information
    lyricLines.forEach((line, index) => {
      console.log(`Line ${index + 1}: "${line.text}"`);
      console.log(`  Timing: ${line.start}s to ${line.end}s`);
      console.log(`  Duration: ${line.end - line.start}s`);
    });
    
    return lyricLines;
  } catch (error) {
    console.error('Failed to get karaoke lyrics:', error.message);
    return [];
  }
}

// Usage
createKaraokeDisplay('Yesterday', 'The Beatles');

Duration-Based Matching

import { LyricalClient } from 'timestamped-lyrics';

const client = new LyricalClient();

// When you know the exact duration of your audio file
async function getAccurateLyrics(song: string, artist: string, audioDuration: number) {
  try {
    const lyrics = await client.getLyrics(song, artist, {
      duration: audioDuration,
      syncedOnly: true
    });
    
    console.log(`Matched song with ${Math.abs(lyrics.duration - audioDuration)}s difference`);
    return lyrics;
  } catch (error) {
    console.error('No matching lyrics found:', error.message);
    return null;
  }
}

Error Handling

The library throws descriptive errors for common scenarios:

try {
  const lyrics = await client.getLyrics('Unknown Song', 'Unknown Artist');
} catch (error) {
  if (error.message.includes('No lyrics found')) {
    console.log('Song not found in database');
  } else if (error.message.includes('Failed to fetch')) {
    console.log('Network error occurred');
  } else if (error.message.includes('No synced lyrics available')) {
    console.log('Song exists but no timestamped lyrics available');
  }
}

Development

Building

npm run build
# or
tsc

Testing

npm test

The project uses Jest for testing with TypeScript support.

Project Structure

src/
├── Client.ts              # Main LyricalClient class
└── types/
    ├── LyricLine.ts       # LyricLine type definition
    └── LyricalSearchResult.ts # LyricSearchResult type definition

License

MIT

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Credits

This library uses the LRCLib API for fetching lyrics data.