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.4.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.4-py3-none-any.whl (14.7 kB view details)

Uploaded Python 3

File details

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

File metadata

File hashes

Hashes for lexigram_multimedia_beat-0.1.4.tar.gz
Algorithm Hash digest
SHA256 d126df683e0fe545d9529ab8d0a7c0904c7b9c105d8f6759d2db8480ebf0d5b9
MD5 ff1cc1ea18fba5a4f1385ec6c55d22e9
BLAKE2b-256 50ba662135e870633381a1d7575650f6e632339450ed584f2a70ac0195985aad

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for lexigram_multimedia_beat-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 4773b05745cd8829f50ec63025f96a1931bb3aa0f0d154383a245ad0dc93b8b7
MD5 c0f6c35f5c3fa09908d6fab08756f1fb
BLAKE2b-256 b506373cba469515e2f0cac26c0b547daa9161dfbc303144adf0e716c1884951

See more details on using hashes here.

Release history Release notifications | RSS feed

0.1.5008

1 file

0.1.5004

2 files

0.1.5001

2 files

0.1.3007

1 file

0.1.3006

1 file

0.1.3005

1 file

This release

0.1.4 This release

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