Skip to main content
POST
/
api
/
v1
/
generate
/
get-timestamped-lyrics
Get Timestamped Lyrics
curl --request POST \
  --url https://api.sunoapi.org/api/v1/generate/get-timestamped-lyrics \
  --header 'Authorization: Bearer <token>' \
  --header 'Content-Type: application/json' \
  --data '
{
  "taskId": "5c79****be8e",
  "audioId": "5c79****be8e",
  "musicIndex": 0
}
'
{
  "code": 200,
  "msg": "success",
  "data": {
    "alignedWords": [
      {
        "word": "[Verse]\nWaggin'",
        "success": true,
        "startS": 1.36,
        "endS": 1.79,
        "palign": 0
      }
    ],
    "waveformData": [
      0,
      1,
      0.5,
      0.75
    ],
    "hootCer": 0.3803191489361702,
    "isStreamed": false
  }
}
Retrieve timestamped lyrics for synchronized display during audio playback. This endpoint provides precise timing data for each word or phrase in your generated music, enabling karaoke-style displays, lyric synchronization, and enhanced audio experiences.

Track Identification

You can specify which track to retrieve lyrics for using either:

Audio ID (Preferred)

  • Direct Identification: Use the specific audioId from your generation results
  • Higher Priority: Takes precedence if both audioId and musicIndex are provided
  • Most Accurate: Ensures you get lyrics for the exact track you want

Music Index (Alternative)

  • Index-Based: Use 0 for the first track, 1 for the second track
  • Fallback Option: Used when audioId is not provided or not found
  • Simple Selection: Easy way to choose between the two generated tracks

Response Data Structure

Aligned Words Array

Each word or phrase in the lyrics includes:
  • Word: The actual lyric text (including formatting like [Verse])
  • Success: Boolean indicating if alignment was successful
  • Start Time: Precise start timestamp in seconds
  • End Time: When the word/phrase ends in seconds
  • Alignment Quality: Technical parameter for alignment accuracy

Waveform Data

  • Visualization Support: Array of amplitude values for creating waveform displays
  • Synchronized Graphics: Perfect for building audio visualization components
  • Real-time Display: Use with timing data for dynamic visual effects

Quality Metrics

  • Alignment Score: Accuracy rating for the lyric synchronization
  • Stream Status: Whether the audio is streaming or static
  • Success Flags: Individual word alignment success indicators

Implementation Examples

Basic Lyrics Display

function displayLyrics(alignedWords, currentTime) {
  const currentWord = alignedWords.find(word =>
    currentTime >= word.startS && currentTime <= word.endS
  );

  if (currentWord && currentWord.success) {
    highlightWord(currentWord.word);
  }
}

Karaoke-Style Synchronization

function updateKaraoke(alignedWords, audioCurrentTime) {
  alignedWords.forEach(word => {
    const element = document.getElementById(`word-${word.id}`);

    if (audioCurrentTime >= word.startS && audioCurrentTime <= word.endS) {
      element.classList.add('singing');
    } else if (audioCurrentTime > word.endS) {
      element.classList.add('sung');
    } else {
      element.classList.remove('singing', 'sung');
    }
  });
}

Use Cases

Music Applications

  • Karaoke Players: Highlight lyrics in real-time during playback
  • Music Learning: Help users learn timing and phrasing
  • Accessibility: Provide visual cues for hearing-impaired users

Content Creation

  • Video Subtitles: Generate perfectly timed captions for music videos
  • Lyric Videos: Create professional lyric display videos
  • Educational Content: Build music theory and timing exercises

Interactive Experiences

  • Sing-Along Features: Enable users to follow along with precision
  • Performance Analysis: Compare user singing to original timing
  • Creative Tools: Build rhythm and timing visualization applications

Best Practices

Timing Accuracy

  • Buffer Time: Add small buffers before/after word timing for smooth display
  • Validation: Check the success flag before displaying each word
  • Fallback: Have backup display logic for unsuccessfully aligned words

Performance Optimization

  • Preload: Cache timestamped data before playback starts
  • Efficient Updates: Only update display when timing changes
  • Memory Management: Clean up previous highlights to avoid memory leaks

User Experience

  • Smooth Transitions: Use CSS transitions for highlight changes
  • Visual Clarity: Ensure highlighted text is easily readable
  • Error Handling: Gracefully handle missing or misaligned lyrics
Transform your music into interactive, synchronized experiences with precise lyric timing data!

Authorizations

Authorization
string
header
required

🔑 API Authentication

All endpoints require authentication using Bearer Token.

Get API Key

  1. Visit the API Key Management Page to obtain your API Key

Usage

Add to request headers:

Authorization: Bearer YOUR_API_KEY

⚠️ Note:

  • Keep your API Key secure and do not share it with others
  • If you suspect your API Key has been compromised, reset it immediately from the management page

Body

application/json
taskId
string
required

The task ID of the music generation task. Required to identify which generation task contains the lyrics.

Example:

"5c79****be8e"

audioId
string

The specific audio ID to retrieve lyrics for. Takes priority over musicIndex if both are provided. Optional, but either audioId or musicIndex should be provided to identify the exact track.

Example:

"5c79****be8e"

musicIndex
enum<number>

The index of the track (0 or 1) within the task. Used only if audioId is not provided or not found. Optional, but either audioId or musicIndex should be provided to identify the exact track.

Available options:
0,
1
Example:

0

Response

Request successful

code
enum<integer>

Status code. 200 - Request successful, 400 - Invalid parameters, 401 - Unauthorized access, 404 - Invalid request method or path, 405 - Rate limit exceeded, 413 - Theme or prompt too long, 429 - Insufficient credits, 430 - Your call frequency is too high. Please try again later, 455 - System maintenance, 500 - Server error

Available options:
200,
400,
401,
404,
405,
413,
429,
430,
455,
500
Example:

200

msg
string

Error message when code != 200

Example:

"success"

data
object