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.5004.tar.gz (25.0 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.5004-py3-none-any.whl (14.8 kB view details)

Uploaded Python 3

File details

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

File metadata

File hashes

Hashes for lexigram_multimedia_beat-0.1.5004.tar.gz
Algorithm Hash digest
SHA256 870f9177058613c93bf60f13a85a3a61cfee8c97922d2371fb70d623d9dc3a20
MD5 50c9fe2203dcf8414fb5f5c2571a2855
BLAKE2b-256 c57b45c75ea7d4fd3c99e2edf92b0aafae300d494d82468491fbadf4f49d9e89

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for lexigram_multimedia_beat-0.1.5004-py3-none-any.whl
Algorithm Hash digest
SHA256 5a0df8b58e7238e48fb003944b1d78691fafb60afef7130ff09f3456c93da90f
MD5 25d5f1e5cea2d681bfeedeeb5a98bfd7
BLAKE2b-256 7316aeebedf4554879deccfe85ddf6dfa5909f00c7db93d20ac996b66c461756

See more details on using hashes here.

Release history Release notifications | RSS feed

0.1.5008

1 file

This release

0.1.5004 This release

2 files

0.1.5001

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