Break Down a Song into Sections like Chorus and Verse

Published: 2025-10-24

It can be very useful to understand the structure of a song, especially if you’re building a music related application. Identifying sections like choruses, verses, and bridges can help with tasks like creating dynamic playlists, generating visualizations, or enhancing user experiences. The Audjust API makes it easy to extract this structural information from audio files.

In this example, we’ll demonstrate how to use the Audjust API to analyze a song and extract its structural sections. To do this, we’ll upload an audio file, analyze it using the structure API, and then print out the identified sections along with their timestamps.

You will need an Audjust API key to use the API. You can get one for free from the API console. If you need help on how to generate an API key, check out the first few steps from this guide.

This code is written in Python and uses the requests library to make HTTP requests. You can install it using pip if you haven’t already:

pip install requests

You don’t need to use use Python specifically; feel free to adapt the code to your preferred programming language. As long as you can make HTTP requests, you can interact with the Audjust API.

Here’s the complete code example:

import requests
from pydub import AudioSegment

API_KEY = "YOUR_API_KEY_HERE"  # Replace with your Audjust API key
LOCAL_MP3_PATH = "your_song.mp3"  # Replace with your local mp3 file path


def upload_file(local_path):
    # Step 1: Get upload URLs
    resp = requests.get(
        "https://api.audjust.com/upload", headers={"X-API-Key": API_KEY}
    )
    resp.raise_for_status()
    data = resp.json()
    storage_url = data["storageUrl"]
    retrieval_url = data["retrievalUrl"]

    # Step 2: Upload file to storageUrl
    with open(local_path, "rb") as f:
        put_resp = requests.put(storage_url, data=f)
        put_resp.raise_for_status()
    return retrieval_url


def get_structure_info(source_url):
    resp = requests.post(
        "https://api.audjust.com/structure",
        headers={"X-API-Key": API_KEY, "Content-Type": "application/json"},
        json={"sourceFileUrl": source_url},
    )
    resp.raise_for_status()
    return resp.json()


def main():
    print("Uploading file...")
    source_url = upload_file(LOCAL_MP3_PATH)
    print("Uploaded. Analyzing structure...")
    info = get_structure_info(source_url)

    print("Sections:")
    for section in info.get("sections", []):
        print(
            f"- {section['startMs'] / 1000}s to {section['endMs'] / 1000}s, label: {section['label']}"
        )
    if not info.get("sections"):
        print("No sections found.")


if __name__ == "__main__":
    main()

When you run it, you should get something like this (output will vary based on the input audio file):

$ python songanalysis.py
Uploading file...
Analyzing structure...
Sections:
- 0.0s to 15.452s, label: 171
- 15.452s to 23.161s, label: 264
- 23.161s to 44.164s, label: 505
- 44.164s to 51.443s, label: 333
- 51.443s to 81.014s, label: 771
- 81.014s to 90.441s, label: 159
- 90.441s to 98.591s, label: 430
- 98.591s to 119.594s, label: 484
- 119.594s to 126.873s, label: 336
- 126.873s to 151.73s, label: 864
- 151.73s to 167.16s, label: 217
- 167.16s to 169.703s, label: 505

Each line represents a section of the song, with its start and end times in seconds, along with a label that categorizes the section. The label values will be between 0 and 1000 and can be used to identify similar sections in the song. When the numbers are closer together, the sections are more similar in terms of audio characteristics. Audjust uses this to help identify choruses, verses, and other repeating sections by color-coding them in the waveform visualizations:

Color-coded waveform showing different sections of a song

Next Steps

The API also exposes other information like loops or beat drops that you can use to further enhance your application. You can explore the full API documentation for more details on how to leverage these features.

More API examples →
Read the API docs →
Try Audjust →