# spotify-lyrics-api: Fetch Spotify Lyrics with a Powerful REST API

This repository profile is provided by osrepos.com, an open source repository discovery platform.

Source: osrepos.com
Repository profile: https://osrepos.com/repo/akashrchandran-spotify-lyrics-api
Generated for open source discovery and AI-assisted research.

The spotify-lyrics-api is a robust REST API designed to fetch lyrics directly from Spotify, powered by Musixmatch. It offers various output formats like ID3, LRC, SRT, and raw text, making it highly versatile for developers. With convenient Docker deployment and a PHP package, integrating Spotify lyrics into your projects has never been easier.

GitHub: https://github.com/akashrchandran/spotify-lyrics-api
OSRepos URL: https://osrepos.com/repo/akashrchandran-spotify-lyrics-api

## Summary

The spotify-lyrics-api is a robust REST API designed to fetch lyrics directly from Spotify, powered by Musixmatch. It offers various output formats like ID3, LRC, SRT, and raw text, making it highly versatile for developers. With convenient Docker deployment and a PHP package, integrating Spotify lyrics into your projects has never been easier.

## Topics

- spotify-lyrics-api
- spotify
- lyrics
- musixmatch
- REST API
- PHP
- web development
- hacktoberfest

## Repository Information

Last analyzed by OSRepos: Wed Jun 17 2026 20:21:35 GMT+0100 (Western European Summer Time)
Detail views: 3
GitHub clicks: 1

## Safety Notice

OSRepos shares public repositories for knowledge and discovery only. Review source code, dependencies, licenses, and security implications before running or installing anything.

## Content

## Introduction

The `spotify-lyrics-api` is a powerful REST API designed to fetch lyrics directly from Spotify, leveraging the data from Musixmatch. This project provides a simple and efficient way to integrate Spotify lyrics into your applications, supporting various output formats including ID3, LRC, SRT, and raw text. It allows developers to retrieve lyrics using either a Spotify track ID or a track URL.

Please note, as stated by the project maintainer, this project might be against Spotify's Terms of Service. Use it at your own risk. For a command-line version, you can explore [akashrchandran/syrics](https://github.com/akashrchandran/syrics "akashrchandran/syrics").

## Installation

Getting `spotify-lyrics-api` up and running is straightforward, with multiple deployment options available:

### Quick Start with Docker

The easiest way to run the API is using Docker:

bash
docker run -d -p 8080:8080 -e SP_DC=your_sp_dc_cookie akashrchandran/spotify-lyrics-api


Then, access the API at `http://localhost:8080/?trackid=YOUR_TRACK_ID`.

For Docker Compose:

yaml
services:
  spotify-lyrics-api:
    image: akashrchandran/spotify-lyrics-api:latest
    ports:
      - "8080:8080"
    environment:
      - SP_DC=your_sp_dc_cookie
    restart: unless-stopped


### Install using Composer

If you prefer to integrate it as a PHP package:

bash
composer require akashrchandran/spotify-lyrics-api


### Run Locally

You can also run the API directly on your local machine with PHP installed:

1.  Clone the repository:
    sh
    git clone https://github.com/akashrchandran/spotify-lyrics-api.git
    cd spotify-lyrics-api
    
2.  Set the `SP_DC` token as a temporary environment variable (find detailed guide [here](https://github.com/akashrchandran/syrics/wiki/Finding-sp_dc "Finding SP_DC cookie guide")):
    sh
    export SP_DC=[your_sp_dc_cookie_here]
    
3.  Start the PHP server:
    sh
    php -S localhost:8080 api/index.php
    

## Examples

The API supports fetching lyrics via GET requests or by using the PHP package.

### Using GET Requests

You can use query parameters `trackid` or `url` to specify the Spotify track, and `format` for the desired output.

**Example using trackid:**


http://localhost:8080/?trackid=5f8eCNwTlr0RJopE9vQ6mB


**Example using url:**


http://localhost:8080/?url=https://open.spotify.com/track/5f8eCNwTlr0RJopE9vQ6mB?autoplay=true


**Example changing format to LRC:**


http://localhost:8080/?trackid=5f8eCNwTlr0RJopE9vQ6mB&format=lrc


The API returns JSON responses, indicating `error` status, `syncType` (LINE_SYNCED or UNSYNCED), and an array of `lines` with `startTimeMs` (or `timeTag` for LRC) and `words`.

### Using as a PHP Package

After installing via Composer, you can integrate the functionality into your PHP application:

php
<?php
require './vendor/autoload.php';

use SpotifyLyricsApi\Spotify;
use SpotifyLyricsApi\SpotifyException;

$spotify = new Spotify("SP_DC here");

try {
    $spotify->checkTokenExpire();
    $lyrics = $spotify->getLyrics(track_id: "1418IuVKQPTYqt7QNJ9RXN");
    
    // $lyrics contains the parsed lyrics data
    echo "Sync Type: " . $lyrics['lyrics']['syncType'] . "\n";
    
    foreach ($lyrics['lyrics']['lines'] as $line) {
        echo "[" . $line['startTimeMs'] . "] " . $line['words'] . "\n";
    }
} catch (SpotifyException $e) {
    echo "Error: " . $e->getMessage() . "\n";
    echo "Status Code: " . $e->getCode() . "\n";
}


You can also format lyrics into LRC, SRT, or raw text:

php
// Get lyrics in LRC format
$lrcLines = $spotify->getLrcLyrics($lyrics['lyrics']['lines']);

// Get lyrics in SRT format
$srtLines = $spotify->getSrtLyrics($lyrics['lyrics']['lines']);

// Get raw lyrics (plain text)
$rawLines = $spotify->getRawLyrics($lyrics['lyrics']['lines']);


## Why Use It

`spotify-lyrics-api` offers a developer-friendly solution for accessing Spotify lyrics. Its versatility, with support for various output formats and easy deployment via Docker, Heroku, or Vercel, makes it an excellent choice for projects requiring lyric integration. Whether you're building a music player, a karaoke application, or a data analysis tool, this API simplifies the process of obtaining synchronized or unsynchronized lyrics.

## Links

*   **GitHub Repository:** [akashrchandran/spotify-lyrics-api](https://github.com/akashrchandran/spotify-lyrics-api "GitHub Repository")
*   **Docker Hub:** [akashrchandran/spotify-lyrics-api](https://hub.docker.com/r/akashrchandran/spotify-lyrics-api "Docker Hub")
*   **Command-line version (syrics):** [akashrchandran/syrics](https://github.com/akashrchandran/syrics "Command-line version")
*   **Deploy to Heroku:** [![Deploy](https://www.herokucdn.com/deploy/button.svg)](https://dashboard.heroku.com/new?template=https://github.com/akashrchandran/spotify-lyrics-api "Deploy to Heroku")
*   **Deploy with Vercel:** [![Deploy with Vercel](https://vercel.com/button)](https://vercel.com/new/clone?repository-url=https%3A%2F%2Fgithub.com%2Fakashrchandran%2Fspotify-lyrics-api%2Ftree%2Fmain&env=SP_DC&envDescription=Want%20to%20host%20your%20own%20version%20of%20this%20API%2C%20then%20you'll%20first%20need%20SP_DC%20cookie%20from%20spotify.&envLink=https%3A%2F%2Fgithub.com%2Fakashrchandran%2Fsyrics%2Fwiki%2FFinding-sp_dc&project-name=spotify-lyrics-api&repository-name=spotify-lyrics-api&redirect-url=https%3A%2F%2Fgithub.com%2Fakashrchandran%2Fspotify-lyrics-api%23examples "Deploy with Vercel")