A powerful Python script to reduce audio file sizes using various compression techniques.
- Multiple Format Support: Convert to MP3, AAC, OGG, or WAV
- Adjustable Bitrate: Control compression quality (64k, 128k, 192k, etc.)
- Sample Rate Control: Resample to lower frequencies for smaller files
- Mono Conversion: Convert stereo to mono for 50% size reduction
- Audio Trimming: Cut audio to specific time ranges
- Batch Processing: Process entire directories at once
- Progress Reporting: Shows compression ratios and file sizes
git clone https://github.com/Danztee/audio-compressor.git
cd audio-compressorpython -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activatepip install -r requirements.txtThe script uses FFmpeg for audio processing. Install it based on your operating system:
macOS:
brew install ffmpegUbuntu/Debian:
sudo apt-get update
sudo apt-get install ffmpegWindows: Download from https://ffmpeg.org/download.html
# Activate virtual environment
source venv/bin/activate # On Windows: venv\Scripts\activate
# Test with a sample file
python audio_compressor.py your_audio_file.wav
# Get help
python audio_compressor.py --help# Compress a single file
python audio_compressor.py input.wav
# Specify output file
python audio_compressor.py input.wav -o compressed.mp3
# High compression (low quality, small size)
python audio_compressor.py input.wav -b 64k -r 16000 -c 1
# Batch process all audio files in a directory
python audio_compressor.py /path/to/audio/files/ --batch| Option | Description | Default |
|---|---|---|
input |
Input audio file or directory | Required |
-o, --output |
Output file or directory | Auto-generated |
-f, --format |
Output format (mp3, aac, ogg, wav) | mp3 |
-b, --bitrate |
Audio bitrate (e.g., "64k", "128k") | 128k |
-r, --sample-rate |
Sample rate in Hz | 22050 |
-c, --channels |
Number of channels (1=mono, 2=stereo) | 2 |
--start-time |
Start time in milliseconds | None |
--end-time |
End time in milliseconds | None |
--batch |
Process all files in directory | False |
python audio_compressor.py song.wav -f mp3 -b 64k -r 16000 -c 1- Converts to MP3 with 64kbps bitrate
- Reduces sample rate to 16kHz
- Converts to mono
- Results in ~90% size reduction
python audio_compressor.py song.wav -f mp3 -b 128k -r 22050 -c 2- Converts to MP3 with 128kbps bitrate
- Keeps 22kHz sample rate
- Maintains stereo
- Results in ~70% size reduction
python audio_compressor.py song.wav -f mp3 -b 192k -r 44100 -c 2- Converts to MP3 with 192kbps bitrate
- Keeps 44.1kHz sample rate
- Maintains stereo
- Results in ~50% size reduction
python audio_compressor.py song.wav --start-time 30000 --end-time 120000 -b 128k- Trims audio from 30 seconds to 2 minutes
- Compresses with 128kbps bitrate
python audio_compressor.py /path/to/music/ --batch -f mp3 -b 128k- Processes all audio files in the directory
- Converts all to MP3 with 128kbps
- 64k: Very small files, low quality (podcasts, voice recordings)
- 128k: Good balance, acceptable quality for most music
- 192k: High quality, minimal quality loss
- 320k: Near CD quality
- 16kHz: Voice recordings, very small files
- 22kHz: Good for most compressed audio
- 44.1kHz: CD quality, minimal compression
- MP3: Most compatible, good compression
- AAC: Better quality than MP3 at same bitrate
- OGG: Open source, good compression
- WAV: Uncompressed, largest files
-
"ffmpeg not found"
- Install FFmpeg using the instructions above
-
"pydub is required"
- Run:
pip install pydub
- Run:
-
"Error processing file"
- Check if the input file is corrupted
- Ensure the file format is supported
- Try a different output format
- MP3, WAV, FLAC, AAC, OGG, M4A, WMA
- MP3, AAC, OGG, WAV
- For maximum compression: Use mono (1 channel), low bitrate (64k), low sample rate (16kHz)
- For best quality: Use stereo (2 channels), high bitrate (192k+), high sample rate (44.1kHz)
- For batch processing: Use the
--batchflag to process multiple files efficiently - For voice recordings: Mono + 64k + 16kHz gives excellent compression with minimal quality loss
This project is licensed under the MIT License - see the LICENSE file for details.
Contributions are welcome! Feel free to:
- Report bugs
- Suggest new features
- Submit pull requests
- Improve documentation