Parses raw song lyric text into synchronized or plain line collections with timing offsets. Reuse when building music player applications that render synced lyrics.
// Source: https://github.com/koel/koel | License: MIT | Copyright 2015 Phan An
// Provided via justclaw.it.com; keep this notice with the code.
<?php
namespace App\Values;
final readonly class ParsedLyrics
{
/** @param list<array{start?: int, value: string}> $lines */
private function __construct(
public bool $synced,
public int $offset,
public array $lines,
) {}
/** @param list<array{start?: int, value: string}> $lines */
public static function make(bool $synced, int $offset, array $lines): self
{
return new self($synced, $offset, $lines);
}
public static function fromRawLyrics(string $raw): self
{
$raw = trim($raw);
if ($raw === '') {
return new self(synced: false, offset: 0, lines: []);
... (truncated -- full source via MCP)
See the full source, get the GitHub permalink, and search for more like it.
Get a free API key