Quickstart
Get tempo and beat timestamps from an audio clip in minutes.
Install
Section titled “Install”uv add lexigram-multimedia-beatOptional extras:
uv add "lexigram-multimedia-beat[librosa]" # librosa in-process backenduv add "lexigram-multimedia-beat[madmom-server]" # madmom reference server (DL-based)The base dependency set (aiohttp, lexigram, lexigram-contracts) is enough to boot
the module; the backend you actually run under needs its extra.
Basic Usage
Section titled “Basic Usage”import asyncio
from lexigram import Applicationfrom lexigram.contracts.multimedia.protocols import BeatAnalysisProviderfrom lexigram.contracts.multimedia.types import BeatAnalysisRequest, MediaAssetfrom lexigram.multimedia.beat import BeatAnalysisModule
async def main() -> None: app = Application(name="beat-demo") app.add_module(BeatAnalysisModule.configure()) # default: in-process librosa await app.start()
beat = await app.container.resolve(BeatAnalysisProvider) asset = MediaAsset( mime_type="audio/mp3", provider="local", bytes_data=b"\x00\xff\xf1...", # real audio bytes in practice ) result = await beat.analyze(BeatAnalysisRequest(asset=asset)) if result.is_ok(): analysis = result.unwrap() # BeatAnalysisResult print(f"tempo: {analysis.tempo_bpm} bpm") print(f"beats: {analysis.beat_timestamps}")
await app.stop()
asyncio.run(main())What Just Happened
Section titled “What Just Happened”BeatAnalysisModule.configure()returns aDynamicModulewith oneBeatAnalysisGenerationProviderand exportsBeatAnalysisProvider.- During
app.start(), the provider’sregister()readsBeatAnalysisConfig(defaultbackend="librosa"), constructs aLibrosaBeatAnalysisProviderwith the configuredlibrosa_sample_rate, and binds it as theBeatAnalysisProvidersingleton. container.resolve(BeatAnalysisProvider)returns that backend.analyze()materializes the asset bytes to a temp file, runs librosa’s beat tracker (librosa.beat.beat_track) off the event loop (asyncio.to_thread), and returnsResult[BeatAnalysisResult, MultimediaError].- The result is a plain value —
tempo_bpmplusbeat_timestamps— nothing is persisted to storage and no job is queued. That’s by design: there is no blob to store.
Next Steps
Section titled “Next Steps”- Guide — the two backends, when to use which, integration with the umbrella
- How-Tos — madmom server setup, beat-synced cutting, resilience recipes
- Configuration —
multimedia_beat:config and env vars - Architecture — provider wiring and the server protocol