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 🙏

© 2024 – Pkg Stats / Ryan Hefner

liricle

v4.2.0

Published

Lyrics Synchronizer

Downloads

49

Readme

Liricle

Liricle is a simple JavaScript library to synchronize lyrics with music in real-time using the LRC file format. It supports both basic and enhanced LRC formats, providing methods to load, sync, and adjust lyrics.

Live Demo →

Installation 📦

Using npm

npm install liricle

In Browser

<script src="https://cdn.jsdelivr.net/npm/liricle"></script>

Example Usage 🚀

Initialization

Create a Liricle instance:

const liricle = new Liricle();

Registering Events

Before loading lyrics, you should register event handlers to handle events such as when the lyrics are loaded, when the lyrics are synced, and when there is an error loading the lyrics. This ensures that your application responds to these events correctly.

Example:

// Register the load event
liricle.on("load", (data) => {
  console.log("Lyrics loaded:", data);
});

// If you load lyrics from a URL, you can listen for the loaderror event when loading fails
liricle.on("loaderror", (error) => {
  console.error("Failed to load lyrics:", error.message);
});

// Register the sync event
liricle.on("sync", (line, word) => {
  console.log("Sync event:", line, word);
});

Load Lyrics

You can load lyrics from either a URL or raw text.

From URL:

liricle.load({
    url: "path/to/your-lrc-file.lrc"
});

From Text:

liricle.load({
    text: `
      [01:02.03] lyric line 1
      [04:05.06] lyric line 2
      ...
    `
});

Note: You must provide either url or text, but not both simultaneously. For more details, see load method.

Sync Lyrics

Synchronize lyrics with the given time from audio player or something else in seconds:

liricle.sync(60); // Sync with time at 60 seconds

Set Offset

Adjust the offset or speed of the lyrics:

// Speed up lyrics by 200 milliseconds
liricle.offset = 200;

// Slow down lyrics by 200 milliseconds
liricle.offset = -200;

Methods

load(options)

Loads lyrics from a URL or text.

Parameters:

  • options.url (string, optional): URL to the LRC file.
  • options.text (string, optional): Raw LRC text.
  • options.skipBlankLine (boolean, optional): Whether to ignore blank lyric lines. Default is true.

Note: You must provide either url or text, but not both. For more information, see Example Usage → Load Lyrics.

sync(time, continuous)

Synchronizes the lyrics with the provided time.

Parameters:

  • time (number): Current time from audio player or something else in seconds.
  • continuous (boolean, optional): Always emit sync event. By default Liricle only emit event if the lyrics index changes.

For more information, see Example Usage → Sync Lyrics.

Properties

offset (getter/setter)

Type: number (milliseconds)

Adjusts the offset or speed of the lyrics. Positive values speed up the lyrics, while negative values slow them down.

Getter Example:

const currentOffset = liricle.offset;
console.log("Current offset:", currentOffset);

Setter Example:

liricle.offset = 200;  // Speed up lyrics

data (getter)

Type: object

Contains the parsed LRC file data after calling the load method.

Getter Example:

const lyricData = liricle.data;
console.log("Lyrics data:", lyricData);

Events

load

Callback Signature:

liricle.on("load", (data) => {
  // Handle load event
});

Parameters:

  • data (object): Contains parsed LRC file data.
{
  // LRC tags or metadata
  tags: {
    ar: "Liricle",
    ti: "Javascript lyric synchronizer library",
    offset: 200
  },

  // lyric lines
  lines: [
    {
      time: 39.98,
      text: "Hello world",

      // if LRC format is not enhanced
      // words value will be null.
      words: [
        {
          time: 40.10,
          text: "Hello"
        },
        ......
      ]
    },
    ......
  ],

  // indicates whether the lrc format is enhanced or not.
  enhanced: true
}

loaderror

Callback Signature:

liricle.on("loaderror", (error) => {
  // Handle loaderror event
});

Parameters:

  • error (Error): Error object containing details about the failure.

sync

Callback Signature:

liricle.on("sync", (line, word) => {
  // Handle sync event
});

Parameters:

  • line (object or null): Current lyric line.
  • word (object or null): Current lyric word (if the LRC format is enhanced).
{
  index: 1,
  time: 39.98,
  text: "Hello world"
}

Example

For a complete example, see here →

Contributing

Want to contribute? Let's go 🚀

License

Distributed under the MIT License. See LICENSE for more information.