Skip to main content

Advanced FLAC authenticity analyzer - Detects MP3-to-FLAC transcodes with high precision

Project description

๐ŸŽต FLAC Detective

Advanced FLAC Authenticity Analyzer - v0.6.7

"Every FLAC file tells a story... I find the truth."

FLAC Detective is a professional-grade tool for detecting MP3-to-FLAC transcodes with exceptional precision. Using advanced spectral analysis and multi-rule scoring, it achieves 89.1% authentic detection rate with less than 0.5% false positives.

Python Version License Status

โœจ Features

๐ŸŽฏ Advanced 11-Rule Detection System

  • Rule 1: MP3 Spectral Signature Detection (CBR patterns) - Enhanced with 20 kHz exception
  • Rule 2: Cutoff Frequency Analysis vs Nyquist
  • Rule 3: Source vs Container Bitrate Comparison
  • Rule 4: Suspicious 24-bit File Detection
  • Rule 5: High Variance Protection (VBR)
  • Rule 6: High Quality Protection
  • Rule 7: Silence & Vinyl Analysis (3 phases)
    • Phase 1: Dither detection
    • Phase 2: Vinyl surface noise
    • Phase 3: Clicks & pops
  • Rule 8: Nyquist Exception (95% & 90% thresholds)
  • Rule 9: Compression Artifacts Detection
    • Test A: Pre-echo (MDCT ghosting)
    • Test B: High-frequency aliasing
    • Test C: MP3 quantization noise
  • Rule 10: Multi-Segment Consistency Analysis
  • Rule 11: Cassette Detection (authentic analog source protection)

๐Ÿ“Š 4-Level Verdict System

Score โ‰ฅ 86  โ†’ FAKE_CERTAIN โŒ (100% confidence)
Score 61-85 โ†’ SUSPICIOUS โš ๏ธ  (High confidence)
Score 31-60 โ†’ WARNING โšก (Manual review recommended)
Score โ‰ค 30  โ†’ AUTHENTIC โœ… (99.5% confidence)

โšก Performance Optimizations

  • 80% faster than baseline (optimized for large-scale analysis)
  • Smart short-circuits for obvious cases
  • Parallel execution of expensive rules
  • File read caching
  • Progressive analysis (2โ†’5 segments when needed)

๐ŸŽฏ Production Metrics

Metric Result Status
Authentic Rate 89.1% โœ… Excellent
Fake Detection 2.2% โœ… Precise
False Positives < 0.5% โœ… Minimal
Tested Files 817,631 โœ… Large-scale
Performance +80% โœ… Optimized

๐Ÿ› ๏ธ Installation

From PyPI (Recommended)

pip install flac-detective

From Source

# Clone the repository
git clone https://github.com/GuillainM/FLAC_Detective.git
cd FLAC_Detective

# Create virtual environment
python -m venv venv
source venv/bin/activate  # Windows: venv\Scripts\activate

# Install in development mode
pip install -e .

# Install development dependencies
pip install -e ".[dev]"

๐Ÿš€ Usage

Command Line

# Analyze current directory
flac-detective .

# Analyze specific directory
flac-detective /path/to/music

# Generate JSON report
flac-detective /path/to/music --format json

# Verbose output
flac-detective /path/to/music --verbose

# Custom output file
flac-detective /path/to/music --output report.txt

Python API

from flac_detective.analysis.new_scoring import new_calculate_score
from pathlib import Path

# Analyze a file
filepath = Path("/path/to/file.flac")
score, verdict, confidence, reasons = new_calculate_score(
    cutoff_freq=20500,
    metadata={"sample_rate": 44100, "bit_depth": 16, "channels": 2},
    duration_check={"duration": 180.5},
    filepath=filepath
)

print(f"Verdict: {verdict} (Score: {score}/150)")
print(f"Confidence: {confidence}")
print(f"Reasons: {reasons}")

๐Ÿ“– Documentation

๐Ÿ—๏ธ Architecture

src/flac_detective/
โ”œโ”€โ”€ analysis/
โ”‚   โ”œโ”€โ”€ new_scoring/          # Advanced 11-rule scoring system
โ”‚   โ”‚   โ”œโ”€โ”€ rules/            # Individual rule implementations
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ spectral.py   # Rules 1, 2, 8 (with 20kHz exception)
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ bitrate.py    # Rules 3, 4
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ silence.py    # Rule 7
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ artifacts.py  # Rule 9
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ consistency.py # Rule 10
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ cassette.py   # Rule 11
โ”‚   โ”‚   โ”œโ”€โ”€ calculator.py     # Orchestration & optimization
โ”‚   โ”‚   โ”œโ”€โ”€ strategies.py     # Strategy pattern implementation
โ”‚   โ”‚   โ”œโ”€โ”€ models.py         # Data models (with energy_ratio)
โ”‚   โ”‚   โ””โ”€โ”€ verdict.py        # Score interpretation
โ”‚   โ”œโ”€โ”€ spectrum.py           # Spectral analysis
โ”‚   โ””โ”€โ”€ audio_cache.py        # File read optimization
โ”œโ”€โ”€ reporting/                # Report generation
โ””โ”€โ”€ main.py                   # CLI entry point

๐Ÿงช Testing

# Run all tests
pytest

# Run with coverage
pytest --cov=flac_detective --cov-report=html

# Run specific test
pytest tests/test_new_scoring_rules.py -v

Test Coverage: ~85% overall, 100% for critical rules

๐Ÿ“Š How It Works

Detection Process

  1. Spectral Analysis: Extract frequency spectrum and detect cutoff
  2. Rule 8 (First): Apply Nyquist protection before other rules
  3. Fast Rules (R1-R6): Quick checks for obvious cases
  4. Short-Circuit: Skip expensive rules if verdict is certain
  5. Expensive Rules (R7, R9): Deep analysis when needed
  6. Multi-Segment (R10): Validate consistency across file
  7. Verdict: Interpret final score with confidence level

Protection Hierarchy

LEVEL 1: Absolute Protection
โ””โ”€ R8 (95-98% Nyquist): -30 to -50 pts

LEVEL 2: Targeted MP3 320k Protection  
โ””โ”€ R1 Exception (90% Nyquist): Skip 320k detection

LEVEL 3: High Quality Protection
โ”œโ”€ R5 (High Variance): -40 pts
โ”œโ”€ R6 (High Quality): -30 pts
โ””โ”€ R7 (Vinyl/Silence): -50 to -100 pts

LEVEL 4: Dynamic Protection
โ””โ”€ R10 (Segment Inconsistency): -20 to -30 pts

๐ŸŽฏ Use Cases

โœ… Recommended For

  • Collection Cleaning: Remove transcoded files from your library
  • Quality Verification: Validate FLAC authenticity before archiving
  • Batch Processing: Analyze large music libraries efficiently
  • Vinyl Rip Validation: Confirm authentic vinyl sources

โŒ Not Recommended For

  • Lossy Format Analysis: Only works with FLAC files
  • Real-time Processing: Designed for batch analysis
  • Subjective Quality: Detects transcodes, not audio quality

๐Ÿ”ฎ Roadmap

v0.6 (Planned)

  • GUI interface for easier usage
  • Configurable sensitivity presets (Strict/Normal/Aggressive)
  • Per-rule enable/disable options
  • Custom threshold configuration
  • HTML reports with spectrograms
  • Automatic file organization

Future Considerations

  • Support for other lossless formats (ALAC, WAV)
  • Machine learning integration
  • Cloud-based analysis API
  • Music player integration

๐Ÿค Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

๐Ÿ“ License

This project is licensed under the MIT License - see the LICENSE file for details.

๐Ÿ™ Acknowledgments

  • Audio analysis community for research on MP3 compression
  • Contributors to NumPy, SciPy, and Soundfile libraries
  • Beta testers who provided valuable feedback

๐Ÿ“ž Support

๐Ÿ“ˆ Project Stats

  • Version: 0.6.7
  • Status: Beta
  • Python: 3.8+
  • License: MIT
  • Detection System: 11 rules with enhanced 20 kHz exception
  • Tested: 817,631 files, 89.1% authentic rate

Made with โค๏ธ for audio enthusiasts

FLAC Detective v0.6.7 - Because your music deserves authenticity

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

flac_detective-0.6.7.tar.gz (123.2 kB view details)

Uploaded Source

Built Distribution

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

flac_detective-0.6.7-py3-none-any.whl (82.9 kB view details)

Uploaded Python 3

File details

Details for the file flac_detective-0.6.7.tar.gz.

File metadata

  • Download URL: flac_detective-0.6.7.tar.gz
  • Upload date:
  • Size: 123.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.19

File hashes

Hashes for flac_detective-0.6.7.tar.gz
Algorithm Hash digest
SHA256 cd67a259497eebe066121aa3c92191db0b0610021ae87d5f07ffbcc4e89449ce
MD5 84ed46e030c0613ddaa2198bc6128e93
BLAKE2b-256 2e74b4c7890046bc97c963832e875d03efe9907f586cbb6fa72aba158e7dcece

See more details on using hashes here.

File details

Details for the file flac_detective-0.6.7-py3-none-any.whl.

File metadata

  • Download URL: flac_detective-0.6.7-py3-none-any.whl
  • Upload date:
  • Size: 82.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.19

File hashes

Hashes for flac_detective-0.6.7-py3-none-any.whl
Algorithm Hash digest
SHA256 6a4eb60283291709ba5b50674613b8201dbc402144bc431a5efe754ec59f79cd
MD5 cf71433c8727b47aeb67c4598ba2f7d5
BLAKE2b-256 5abe1c36ed7baed82a7b8a59c7cb6b60cda08b505fd7745e224c8e22b1860482

See more details on using hashes here.

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