Thanks to visit codestin.com
Credit goes to Github.com

Skip to content

6xingyv/accompanist-lyrics-core

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

67 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Tests Maven Central Telegram License

πŸ“¦ Repository

Accompanist released a group of artifacts, including:

  • lyrics-core - Parsing lyrics file, holding data and exporting to other formats.

  • lyrics-ui - Standard lyrics interface built on Jetpack Compose

This repository hosts the lyrics-core code.

✨ Features

  • πŸ€– Smart Auto-Detection: Automatically detects and parses various lyrics formats out of the box.
  • 🎀 Karaoke-Ready: Provides syllable-level timing for precise karaoke-style highlighting.
  • 🌐 Translation Support: Natively handles dual-language or translated lyric lines.
  • 🧩 Highly Extensible: Easily add support for new or custom formats.
  • 🏷️ Metadata Extraction: Reads standard tags like artist, album, title, and offset.
  • πŸš€ Pure Kotlin/JVM: No Android dependencies, suitable for any Kotlin project.

πŸ’Ώ Supported Formats

  • LRC: Standard and dual-language .lrc files.
  • Enhanced LRC: Syllable-level timing, voice separation, and accompaniment tags.
  • TTML (Apple Syllable): The format used by Apple Music.
  • Lyricify Syllable: Custom format from the Lyricify App.

πŸš€ Installation

Add the dependency to your build.gradle.kts:

dependencies {
    implementation("com.mocharealm.accompanist:lyrics-core:VERSION")
}

Replace VERSION with the latest version from Maven Central.


▢️ Usage

Quick Start: Auto-Parsing (Recommended)

For most use cases, AutoParser is the easiest way to parse lyrics without needing to know the format beforehand.

import com.mocharealm.accompanist.lyrics.core.parser.AutoParser

// 1. Get your lyrics content from a file or network
val lyricsContent: String = fetchLyrics()

// 2. Create a default AutoParser instance using its builder
val autoParser = AutoParser.Builder().build()

// 3. Parse the content
val lyrics = autoParser.parse(lyricsContent)

// Now you have a unified SyncedLyrics object!
println(lyrics.metadata.title)
println(lyrics.lines.first().text)

Parsing a Specific Format

If you know the exact format, you can use a specific parser directly.

import com.mocharealm.accompanist.lyrics.core.parser.LrcParser

val lrcLines = listOf(
    "[00:39.96]I lean in and you move away",
    "[00:39.96]ζˆ‘ι εœ¨ι‡Œι’οΌŒδ½ ε°±η¦»εΌ€"
)

val lyrics = LrcParser.parse(lrcLines)
println(lyrics.lines)

You can also use EnhancedLrcParser, TTMLParser, or LyricifySyllableParser.


πŸ› οΈ Extending with Custom Formats

Accompanist Lyrics is designed to be extensible. You can add support for any custom format by implementing the ILyricsParser interface and registering it with the AutoParser.

Step 1: Implement ILyricsParser

Create a class that implements the parsing logic for your custom format.

import com.mocharealm.accompanist.lyrics.core.model.SyncedLyrics
import com.mocharealm.accompanist.lyrics.core.parser.ILyricsParser

class MyCustomParser : ILyricsParser {
    override fun parse(lines: List<String>): SyncedLyrics {
        // Your parsing logic here...
    }
    
    override fun parse(content: String): SyncedLyrics {
        // Your parsing logic here...
    }
}

Step 2: Define a Format Detector

Create a LyricsFormat that contains a detector function. This function returns true if the given content matches your custom format.

import com.mocharealm.accompanist.lyrics.core.utils.LyricsFormatGuesser

val myCustomFormat = LyricsFormatGuesser.LyricsFormat(
    name = "MY_CUSTOM_FORMAT",
    detector = { content -> 
        // Example: check for a unique tag
        content.startsWith("##MY_COOL_LYRICS##")
    }
)

Step 3: Register with AutoParser.Builder

Use the withFormat method on the builder to register your new format and its parser. Custom formats are checked first, ensuring they are prioritized over built-in ones.

import com.mocharealm.accompanist.lyrics.core.parser.AutoParser

// Build an AutoParser instance with your custom format
val autoParser = AutoParser.Builder()
    .withFormat(myCustomFormat, MyCustomParser())
    .build()

// This parser now understands both built-in and your custom format!
val lyrics = autoParser.parse(myCustomLyricsContent)

πŸ’¬ Community & Support

Join the community, ask questions, and share your projects!

🀝 Contributing

Contributions are welcome! Please feel free to submit a pull request or open an issue to discuss your ideas. For major changes, please open an issue first.

πŸ“œ License

This project is licensed under the Apache License 2.0. See the LICENSE file for details.

About

A lyrics parsing, converting, exporting library for Kotlin

Topics

Resources

License

Stars

Watchers

Forks

Contributors 3

  •  
  •  
  •  

Languages