Skip to main content

AudioClassifier - Dynamic Classifier used for Audio Segment Identification and Removal

PyPI Python License: MIT

Runs locally by default: one audio file in, filtered audio out. Needs an OpenAI API key and ffmpeg.

Quick Start

uv sync
export OPENAI_API_KEY=<your-key>

PAYLOAD='{"source": "My Show", "name": "Episode 1", "audio_url": "<mp3-url>"}' \
  uv run audioclassifier --detection examples/configs/ads.toon

Results land in output/<source>/<name>/: the original mp3, the cleaned *_filtered.mp3, and a transcripts/ dir with what was transcribed and each LLM cut/keep decision (with reasoning). Or with Docker:

docker build -t audioclassifier-app .
docker run --gpus all \
  -e OPENAI_API_KEY=<your-key> \
  -e DETECTION_CONFIG=ads \
  -e PAYLOAD='{"source": "My Show", "name": "Episode 1", "audio_url": "<mp3-url>"}' \
  -v "$(pwd)/output:/app/output" \
  audioclassifier-app

Drop --gpus all to run on CPU (slower). The same container runs on any GPU box — RunPod, Modal, a gaming PC.

As a Library

uv add audio-classifier-tool      # pip install audio-classifier-tool
import audioclassifier

result = audioclassifier.process_audio(
    source="My Show",
    name="Episode 1",
    audio_url="<mp3-url>",
    detection="examples/configs/ads.toon",  # a .toon path or a name in ./configs
    detection_instructions="...",           # or pass the prompt directly
    detection_keywords=["use code", ...],   # and the keyword gate
)
print(result["output_path"], result["seconds_removed"])

Importing has no side effects; configure the "audioclassifier" logger to see progress.

For a real end-to-end run with live console output and a decision summary:

uv run python examples/process_audio.py "<mp3-url>"

How It Works

  • Downloads the audio from the PAYLOAD JSON (source, name, audio_url, optional description)
  • Transcribes with faster-whisper (GPU-accelerated, CPU works too)
  • Detects target segments with an LLM, guided by your detection config (ad removal is the flagship example)
  • Cuts them and re-assembles the audio

Detection

The classifier is fully yours to define — nothing is bundled. A TOON config supplies the keywords and prompts: select one with --detection <name|path> or DETECTION_CONFIG (names resolve from ./configs/), or pass the prompt and keywords directly (detection_instructions/detection_keywords in the API, DETECTION_INSTRUCTIONS/DETECTION_KEYWORDS env vars). Complete examples live in examples/configs/ (ads, politics).

Text Classifier (optional, opt-in)

A self-distilled local classifier can add a third detection signal alongside keywords and audio analysis. Every processed audio file writes LLM-labeled decisions under output/**/transcripts/ — that corpus is the classifier's training data, and it grows with each run.

Enable with USE_TEXT_CLASSIFIER=true: the classifier's flagged ranges join the LLM prompt (advisory only — the LLM still decides), and it retrains automatically after each run from the full accumulated history (retraining is from scratch, in seconds, so nothing is ever forgotten). Refresh manually anytime:

uv run python examples/train_classifier.py          # or audioclassifier.train_text_classifier()

How it propagates: the durable memory is the decision files in output/ — the model file (local_models/text_classifier.joblib) is a disposable cache rebuilt from them. Editing a decision file's cut_ranges_seconds after listening feeds your correction into the next training pass. In Docker, mount local_models/ alongside output/ to carry the model between containers (the data already survives via the output/ mount).

Parallelism

One audio file per process_audio call. Multiple processes are safe, even in the same directory — downloads and segment audio live in per-run temp dirs, and the classifier model is written atomically. Within one process, run audio files sequentially (Whisper models load once and are reused); concurrent runs in threads are supported only with one shared detection config. Don't feed the same audio to two processes at once — they'd write the same output files.

Options

  • LLM_MODEL — any pydantic-ai model string (default openai:gpt-5.6; e.g. openai:gpt-5-nano for cheapest, anthropic:claude-sonnet-4-6, ollama:qwen3 — non-OpenAI providers may need their extra installed)
  • DISCORD_ALERTS=true DISCORD_WEBHOOK_URL=<url> — processing alerts in Discord
  • storage="s3://bucket/prefix" (API) or "storage" in PAYLOAD — upload the run's outputs (audio + transcripts + decisions) to S3 under <prefix>/<source>/<name>/, using ambient AWS credentials

License

MIT

Metadata

Release files for audio-classifier-tool 1.2.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for audio-classifier-tool 1.2.1
File Size Uploaded
audio_classifier_tool-1.2.1.tar.gz 118.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for audio-classifier-tool 1.2.1
File Interpreter ABI Platform
audio_classifier_tool-1.2.1-py3-none-any.whl Python 3 none any Details

Total release size: 145.2 kB

Release files / audio_classifier_tool-1.2.1.tar.gz

Download URL audio_classifier_tool-1.2.1.tar.gz
Size 118.6 kB
Tags Source
SHA-256 checksum
How to use checksums
2ed5689148dde303bd28dbef10c0ba9e4a09a3478c531cd9c4f550cf0fe69577
BLAKE2b-256 checksum
How to use checksums
e9e39939ecc9246651c192dd66c707642100bf7ce6e6bcbcc5002b71af4189f3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.12.17 {"installer":{"name":"uv","version":"0.12.17","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / audio_classifier_tool-1.2.1-py3-none-any.whl

Download URL audio_classifier_tool-1.2.1-py3-none-any.whl
Size 26.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
68a2bfcd7a7a007df766d833ede99b7bdd476f1cf1516b3d2f491e9d4bb334c9
BLAKE2b-256 checksum
How to use checksums
08bd33057bdeb86ef172da2bb41b66c17be9775e315589d5610b233d6050ad74
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.12.17 {"installer":{"name":"uv","version":"0.12.17","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release history Release notifications | RSS feed

1.3.0

2 release files

This release

1.2.1 This release

2 release files

1.2.0

2 release files

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