Skip to main content

AudioClassifier - Dynamic Classifier used for Audio Segment Identification and Removal

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 OpenAI — ads by default
  • 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.0

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.0
File Size Uploaded
audio_classifier_tool-1.2.0.tar.gz 118.0 kB Details

Built distribution (wheel)

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

Total release size: 144.5 kB

Release files / audio_classifier_tool-1.2.0.tar.gz

Download URL audio_classifier_tool-1.2.0.tar.gz
Size 118.0 kB
Tags Source
SHA-256 checksum
How to use checksums
1ca4c6dfe602c9eae18f8227d69cc092e8126babdc0b062c8e16f0c9583c4357
BLAKE2b-256 checksum
How to use checksums
9f0d01d050df00e5f237682011cc196530a851820cc014bf875d18c1dcd75f62
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.0-py3-none-any.whl

Download URL audio_classifier_tool-1.2.0-py3-none-any.whl
Size 26.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9a781563a833c8b9452900540931deca268a0c78b09df1a4793aa31c9673f52a
BLAKE2b-256 checksum
How to use checksums
6a68f42dc540d936c95ccae23db853c201d513d558e93c431e11a1088e6fb9af
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

1.2.1

2 release files

This release

1.2.0 This release

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