Skip to main content

lexigram-multimedia-beat

Audio tempo/beat analysis for the Lexigram Framework — analyzes an audio MediaAsset and returns tempo (BPM) and beat timestamps for driving beat-synced cut timing.


Overview

lexigram-multimedia-beat analyzes an audio clip and returns a BeatAnalysisResult (tempo_bpm + beat_timestamps). Two backends are available: librosa (default, runs in-process, no reference server) and madmom (optional, deep-learning-based, reference-server pattern — better on syncopated or tempo-changing material).

Full documentation: docs.lexigram.dev

Install

uv add lexigram-multimedia-beat
# Optional extras
uv add "lexigram-multimedia-beat[librosa]"        # librosa in-process backend
uv add "lexigram-multimedia-beat[madmom-server]"  # madmom reference server

Quick Start

from lexigram import Application
from lexigram.di.module import Module, module
from lexigram.multimedia.beat import BeatAnalysisModule
from lexigram.contracts.multimedia.protocols import BeatAnalysisProvider
from lexigram.contracts.multimedia.types import BeatAnalysisRequest, MediaAsset


@module(imports=[BeatAnalysisModule.configure()])
class AppModule(Module):
    pass


async def main() -> None:
    async with Application.boot(modules=[AppModule]) as app:
        beat = await app.container.resolve(BeatAnalysisProvider)
        asset = MediaAsset(mime_type="audio/mp3", provider="local", bytes_data=b"<mp3>")
        result = await beat.analyze(BeatAnalysisRequest(asset=asset))
        if result.is_ok():
            analysis = (
                result.unwrap()
            )  # BeatAnalysisResult — tempo_bpm + beat_timestamps
            print(analysis.tempo_bpm)


if __name__ == "__main__":
    import asyncio

    asyncio.run(main())

Configuration

Zero-config usage: Call BeatAnalysisModule.configure() with no arguments to use the in-process librosa backend.

Option 1 — YAML file

# application.yaml
multimedia_beat:
  backend: "librosa"
  librosa_sample_rate: 44100

Option 2 — Profiles + Environment Variables

export LEX_PROFILE=production
export LEX_MULTIMEDIA_BEAT__BACKEND=madmom
export LEX_MULTIMEDIA_BEAT__LIBROSA_SAMPLE_RATE=44100

Option 3 — Python

from lexigram.multimedia.beat import BeatAnalysisModule
from lexigram.multimedia.beat.config import BeatAnalysisConfig

BeatAnalysisModule.configure(
    config=BeatAnalysisConfig(backend="librosa", librosa_sample_rate=44100)
)

Config reference

Field Default Env var Description
backend "librosa" LEX_MULTIMEDIA_BEAT__BACKEND librosa (in-process), madmom (reference server)
librosa_sample_rate 22050 LEX_MULTIMEDIA_BEAT__LIBROSA_SAMPLE_RATE Sample rate for the librosa backend
madmom_base_url "http://localhost:5600" LEX_MULTIMEDIA_BEAT__MADMOM_BASE_URL Madmom server URL
timeout 30.0 LEX_MULTIMEDIA_BEAT__TIMEOUT Request timeout in seconds

Module Factory Methods

Method Description
BeatAnalysisModule.configure(config) Configure with explicit beat-analysis config
BeatAnalysisModule.stub() No-op module for unit testing (uses librosa)

Key Features

  • Two backendslibrosa (in-process, default, no reference server) and madmom (deep-learning, reference-server pattern)
  • No blob persistence — returns a BeatAnalysisResult (tempo + beat timestamps), not a MediaAsset; no queued task handler
  • Beat-synced editing — drive cut timing in the calling application
  • Reference serverlexigram-beat-madmom-serve console script runs the madmom model server
  • Result-basedanalyze() -> Result[BeatAnalysisResult, MultimediaError]; errors are domain values, not exceptions

Testing

from lexigram import Application
from lexigram.multimedia.beat import BeatAnalysisModule


async def test_boot():
    async with Application.boot(modules=[BeatAnalysisModule.stub()]) as app:
        assert app.container is not None

Key Source Files

File What it contains
src/lexigram/multimedia/beat/module.py BeatAnalysisModule.configure() and .stub()
src/lexigram/multimedia/beat/config.py BeatAnalysisConfig
src/lexigram/multimedia/beat/di/provider.py BeatAnalysisGenerationProvider — registers BeatAnalysisProvider
src/lexigram/multimedia/beat/providers/ Backend implementations (librosa, madmom)
src/lexigram/multimedia/beat/servers/ Reference-server entry point (lexigram-beat-madmom-serve)
src/lexigram/multimedia/beat/exceptions.py BeatAnalysisError hierarchy

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

lexigram_multimedia_beat-0.1.5001.tar.gz (24.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

lexigram_multimedia_beat-0.1.5001-py3-none-any.whl (14.7 kB view details)

Uploaded Python 3

File details

Details for the file lexigram_multimedia_beat-0.1.5001.tar.gz.

File metadata

File hashes

Hashes for lexigram_multimedia_beat-0.1.5001.tar.gz
Algorithm Hash digest
SHA256 dd08cb412f2b957e7bb6a49cffeed17c9c42710c8d0faab750e0d13d8272fa57
MD5 755a98c3650c46e22350fe599601b14b
BLAKE2b-256 757b502e09700fcb558cb28f825d4467224d8d5a814881568089963f82e28bcc

See more details on using hashes here.

File details

Details for the file lexigram_multimedia_beat-0.1.5001-py3-none-any.whl.

File metadata

File hashes

Hashes for lexigram_multimedia_beat-0.1.5001-py3-none-any.whl
Algorithm Hash digest
SHA256 2ae4ad7294503895d0d98f3ad105a6ff3900d281e913f23b289ce4e50b457619
MD5 79f663b912abcd435fba7d8c0a5b6662
BLAKE2b-256 a6993c5e9393ed3394e7b7454932f94e8f1204555145c3890889663ef4de02f4

See more details on using hashes here.

Release history Release notifications | RSS feed

0.1.5008

1 file

0.1.5004

2 files

This release

0.1.5001 This release

2 files

0.1.3007

1 file

0.1.3006

1 file

0.1.3005

1 file

0.1.4

2 files

0.1.0

1 file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page