Skip to main content

Audio quality analysis and bitrate detection, with optional beets plugin

Project description

bitrater

Audio quality analysis and bitrate detection for audio files. Detects the true encoding quality of MP3, FLAC, WAV, AAC, and other formats using spectral analysis and deep learning. Identifies transcodes (e.g., a 128 kbps source re-encoded as 320 kbps MP3 or upsampled to FLAC) and verifies lossless files are genuinely lossless.

Available as a standalone CLI tool or as a beets plugin.

Features

  • 7-class bitrate classification: 128, 192, 256, 320 kbps CBR, V0/V2 VBR presets, and lossless (FLAC/WAV/AIFF)
  • Lossless verification: confirms whether lossless files are truly lossless or transcodes from lossy sources
  • Transcode detection: identifies files whose stated bitrate doesn't match their true encoding quality
  • Pre-trained deep learning model: ships with a CNN+BiLSTM model achieving 98.4% accuracy
  • Confidence scoring: every prediction includes a confidence score
  • Feature caching: thread-safe NPZ cache avoids redundant spectral analysis
  • Parallel processing: multi-threaded analysis via joblib

Installation

Requires Python 3.10+ and FFmpeg.

Standalone (no beets)

pip install bitrater

With beets plugin

pip install "bitrater[beets]"

Then enable the plugin in your beets config (~/.config/beets/config.yaml):

plugins: bitrater

From source (with uv)

git clone https://github.com/yamsnjams/bitrater.git
cd bitrater
uv sync              # standalone
uv sync --all-extras # with beets + training + dev dependencies

Quick Start

Standalone CLI

# Analyze a single file
bitrater analyze song.mp3

# Analyze a directory
bitrater analyze /path/to/music/

# Verbose output (show warnings)
bitrater -v analyze /path/to/music/

Example output:

[OK] song.mp3: MP3 320kbps (confidence: 95%)
[TRANSCODE] another.mp3: MP3 128kbps (confidence: 88%)
[OK] track.flac: LOSSLESS (confidence: 97%)
[TRANSCODE] fake_lossless.flac: MP3 192kbps (confidence: 91%)

Beets Plugin

# Analyze your library (or a subset via query)
beet bitrater
beet bitrater artist:radiohead

# Verbose output
beet bitrater -v

The plugin stores results in beets' database as custom fields:

Field Description
original_bitrate Estimated true encoding bitrate
bitrate_confidence Confidence score (0.0-1.0)
is_transcoded Whether the file appears to be a transcode
spectral_quality Overall spectral quality score
format_warnings Warning messages from analysis

Pre-trained Model

Bitrater ships with a pre-trained deep learning model that works out of the box. No training is required. See MODEL_CARD.md for full details on the model architecture, training data, and performance metrics.

The bundled model achieves 98.4% accuracy across all 7 classes on a held-out test set.

Beets Plugin Configuration

All options and their defaults:

bitrater:
    auto: false              # Auto-analyze on import
    min_confidence: 0.8      # Minimum confidence threshold
    warn_transcodes: true    # Show transcode warnings
    threads: null            # Analysis threads (null = auto)
    on_transcode: ask        # Action for transcodes: ask, quarantine, keep, skip
    quarantine_dir: null     # Quarantine folder (default: {library}/.quarantine/)

Transcode Handling

When a counterfeit/transcoded file is detected, on_transcode controls the behavior:

Value Behavior
ask Prompt the user: Keep, Quarantine, or Skip (default)
quarantine Automatically move to quarantine folder
keep Log a warning but take no action
skip Remove from library and delete the file

The quarantine folder defaults to .quarantine/ inside your beets library directory. Set quarantine_dir to override with a custom path.

How It Works

Spectral Analysis

Audio files are analyzed in the frequency domain. MP3 encoding introduces characteristic artifacts:

  • Frequency cutoffs: lower bitrates have lower high-frequency cutoffs (e.g., 128 kbps cuts off around 16 kHz)
  • Spectral flatness: lossy compression reduces spectral detail in high frequencies
  • SFB21 band: the highest scale factor band is a strong indicator of encoding quality

Deep Learning Classifier

Two-stage CNN + BiLSTM architecture (~1.1M total parameters):

  • Stage 1: CNN feature extractor on dual-band spectrograms (64 mel + 64 linear HF bins, 2-second windows)
  • Stage 2: BiLSTM with multi-head attention over sequences of 48 CNN features, plus 211 auxiliary features (spectral + global modulation DCT)
  • Focal loss with class weighting, file-level aggregation across all sequences
  • 98.4% overall accuracy with all classes above 96% F1

See MODEL_CARD.md for complete details.

Development

# Run tests
uv run python -m pytest tests/

# Run tests with coverage
uv run python -m pytest tests/ --cov=bitrater --cov=beetsplug

# Format and lint
uv run black bitrater/ beetsplug/ tests/
uv run ruff check --fix bitrater/ beetsplug/ tests/

License

MIT

Project details


Download files

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

Source Distribution

bitrater-0.1.1.tar.gz (4.7 MB view details)

Uploaded Source

Built Distribution

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

bitrater-0.1.1-py3-none-any.whl (4.6 MB view details)

Uploaded Python 3

File details

Details for the file bitrater-0.1.1.tar.gz.

File metadata

  • Download URL: bitrater-0.1.1.tar.gz
  • Upload date:
  • Size: 4.7 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for bitrater-0.1.1.tar.gz
Algorithm Hash digest
SHA256 80aff9c0e4de5daa91c645731731a9e8efe8ff49ff0f053951b72388dc5ada89
MD5 23364e45b227cbda6bdd7b5ac7c751de
BLAKE2b-256 754fe8778356f7390466cac9403a70a33720302c09b8189267da91e861804c55

See more details on using hashes here.

Provenance

The following attestation bundles were made for bitrater-0.1.1.tar.gz:

Publisher: publish.yml on yamsnjams/bitrater

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file bitrater-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: bitrater-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 4.6 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for bitrater-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 81da8e49571b8c0d6a16ca0929707ae167854ac69c992462fe7d8996546e72cf
MD5 ab3dbe2af0ad71360e1c73a34a0d81e1
BLAKE2b-256 86eae7d227a8b1f3005fb0254052c315324fb92e872cb0bfe4020d934dfdcaed

See more details on using hashes here.

Provenance

The following attestation bundles were made for bitrater-0.1.1-py3-none-any.whl:

Publisher: publish.yml on yamsnjams/bitrater

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page