JAMS: A JSON Audio Metadata Standard

0.3.5 · active · verified Wed Apr 15

JAMS is a Python library implementing a JSON-based music annotation format, providing a formal schema for generic annotations. It allows for storing multiple annotations per file and includes schema definitions for a wide range of annotation types like beats, chords, segments, and tags. The library also features error detection, validation, and a translation layer to interface with `mir_eval` for evaluating annotations. It is actively maintained, with the current version being 0.3.5, and supports recent Python versions.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to create a `jams.JAMS` object, populate its `file_metadata`, and add `Annotation` objects for 'beat' and 'tempo'. It shows how to add individual observations to annotations and structure the metadata. The example uses placeholder values to avoid external dependencies like `librosa` for initial setup.

import jams
import os

# Create a new JAMS object
jam = jams.JAMS()

# Set file metadata
jam.file_metadata.duration = 180.0 # Example duration in seconds
jam.file_metadata.title = 'Example Track'
jam.file_metadata.artist = 'Example Artist'

# Create a new Annotation for beats
beat_annotation = jams.Annotation(namespace='beat')
beat_annotation.annotation_metadata = jams.AnnotationMetadata(
    data_source='manual annotation',
    curator=jams.Curator(name='AI Assistant')
)

# Add some example beat observations
beat_annotation.append(time=0.5, duration=0.0)
beat_annotation.append(time=1.0, duration=0.0)
beat_annotation.append(time=1.5, duration=0.0)

# Add the beat annotation to the JAMS object
jam.annotations.append(beat_annotation)

# Create a new Annotation for tempo
tempo_annotation = jams.Annotation(namespace='tempo', time=0, duration=jam.file_metadata.duration)
tempo_annotation.annotation_metadata = jams.AnnotationMetadata(
    data_source='estimated',
    curator=jams.Curator(name='AI Assistant')
)
tempo_annotation.append(time=0.0, duration=jam.file_metadata.duration, value=120.0, confidence=1.0)

# Add the tempo annotation to the JAMS object
jam.annotations.append(tempo_annotation)

# Print the JAMS object (its __repr__ is quite informative)
print(jam)

# Optionally save to a .jams file
# jam.save('example.jams')
# To load:
# loaded_jam = jams.load('example.jams')

view raw JSON →