Skip to main content

twat-audio

Audio processing utilities for the twat ecosystem.

twat-audio provides deterministic, file-level audio helpers built on two backends:

  • Pedalboard (Spotify) — fast, high-quality resampling via libsndfile/libresample.
  • ffmpeg — normalization, trimming, audio extraction, muxing, and arbitrary filter application.

Speech-specific concerns (STT, TTS, dubbing orchestration, transcript handling) belong in twat_speech. This package stays focused on audio files and signals.

Requirements

  • Python 3.10+
  • ffmpeg and ffprobe on PATH (for all operations except resample_audio)

Installation

pip install twat-audio

Or with uv:

uv add twat-audio

Python API

from twat_audio import AudioProcessConfig, resample_audio, normalize_audio, trim_audio

# Resample to 16 kHz (common ML model input rate)
result = resample_audio(
    AudioProcessConfig("speech.wav", "speech_16k.wav", target_samplerate=16000.0)
)
print(result["status"])  # "success"

# Normalize loudness (EBU R128, target -16 LUFS)
normalize_audio("speech.wav", "speech_norm.wav", target_i=-16.0)

# Trim: start at 2 s, take 5 s
trim_audio("speech.wav", "clip.wav", start=2.0, duration=5.0)

All Public Functions

Function Backend Description
resample_audio(config) Pedalboard Resample to any sample rate
normalize_audio(in, out, ...) ffmpeg Loudness normalization (EBU R128)
trim_audio(in, out, ...) ffmpeg Trim by time range
extract_audio(in, out, ...) ffmpeg Extract audio from video
replace_audio(video, audio, out) ffmpeg Replace audio track in video
simple_effect(in, out, filter) ffmpeg Apply any ffmpeg -af filter
audio_metadata(path) ffprobe Read media metadata as dict
generate_audio(prompt, ...) twat_genai AI audio generation (optional)

CLI

# Show all subcommands
python -m twat_audio --help

# Resample
twat-audio resample input.wav output.wav --samplerate 16000

# Normalize (--dry-run prints the command without running it)
twat-audio normalize input.wav output.wav --dry-run

# Trim: 5-second clip starting at 2 s
twat-audio silence-trim input.wav clip.wav --start 2 --duration 5

# Extract audio from video
twat-audio transcode movie.mp4 voice.wav

# Replace audio track
twat-audio replace silent.mp4 voice.wav dubbed.mp4

# Apply ffmpeg filter
twat-audio effect input.wav loud.wav --audio-filter "volume=2.0"

# Read metadata
twat-audio info input.wav

# Print version
twat-audio version

Supported Formats

Resampling (Pedalboard): WAV, AIFF, FLAC, OGG, MP3.

ffmpeg operations: all formats ffmpeg supports, including MP4/MKV/MOV/AVI/WebM containers for audio extraction.

Role in the twat Ecosystem

twat-audio is a plugin for the twat host package. It registers under the twat.plugins entry point as audio. Other twat plugins can import it to gain audio file operations without depending on ffmpeg directly.

# Via twat plugin discovery
import twat
twat.audio.normalize_audio("in.wav", "out.wav")

Development

git clone https://github.com/twardoch/twat-audio
cd twat-audio
uv venv --python 3.12
uv pip install -e ".[dev,test]"
python -m pytest tests/ -v

Lint and format:

ruff check src/twat_audio tests
ruff format src/twat_audio tests

See STYLE_GUIDE.md for coding conventions and CONTRIBUTING for the full development workflow.

License

MIT — see LICENSE.

Metadata

Release files for twat-audio 2.7.12

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

Source distribution (sdist)

Source distribution for twat-audio 2.7.12
File Size Uploaded Provenance Actions
twat_audio-2.7.12.tar.gz 1.0 MB With provenance Details for twat_audio-2.7.12.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for twat-audio 2.7.12
File Interpreter ABI Platform Actions
twat_audio-2.7.12-py3-none-any.whl Python 3 none any Details for twat_audio-2.7.12-py3-none-any.whl

Total release size: 1.0 MB

Release files / twat_audio-2.7.12.tar.gz

Download URL twat_audio-2.7.12.tar.gz
Size 1.0 MB
Tags Source
SHA-256 checksum
How to use checksums
91824e016d50c133f0084a95beb02fe64ca55dd7e807ae98ff0281f81550ed94
BLAKE2b-256 checksum
How to use checksums
3b6f7af2421c708f7554f50e78e53dd33ca5934b5bdcad015f0f3839ca01db2c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 18, 2026.

Transparency log

Release files / twat_audio-2.7.12-py3-none-any.whl

Download URL twat_audio-2.7.12-py3-none-any.whl
Size 11.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7e2a667433ac17b48b9e35eb82c2dcee1f5a9a8672ed38d8d76be0365ffdad31
BLAKE2b-256 checksum
How to use checksums
61094b58fb2172db96c7ea2cdd6414434a43493125eefe156c7a277bd6c36845
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 18, 2026.

Transparency log

Security for twat-audio 2.7.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for twat_audio-2.7.12.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 18, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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