Spaces:
Paused
Paused
File size: 12,353 Bytes
0d0201b 19764b0 0d0201b 19764b0 0d0201b 03cad88 cb39c05 19764b0 cb39c05 19764b0 cb39c05 09108e1 cb39c05 03cad88 cb39c05 03cad88 cb39c05 09108e1 03cad88 09108e1 cb39c05 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 | ---
title: Voice Tools - Speaker Separation & Audio Extraction
emoji: 🎤
colorFrom: blue
colorTo: purple
sdk: gradio
sdk_version: 5.49.1
app_file: app.py
pinned: false
license: mit
hardware: zero-gpu
tags:
- audio
- audio-classification
- speech-processing
- speaker-diarization
- speaker-recognition
- audio-to-audio
- voice-activity-detection
- noise-reduction
- gradio
- pytorch
- pyannote-audio
- audio-extraction
- voice-isolation
- podcast
- interview
- video-editing
- content-creation
models:
- pyannote/speaker-diarization-3.1
- pyannote/segmentation-3.0
- MIT/ast-finetuned-audioset-10-10-0.4593
- facebook/demucs
- silero/silero-vad
---
# Voice Tools
**AI-powered speaker separation, voice extraction, and audio denoising for podcasts, interviews, and video editing**
Voice Tools is an AI-powered audio processing toolkit that helps content creators, podcasters, and video editors extract specific voices from mixed audio, separate multi-speaker conversations, and remove background noise. Using state-of-the-art open-source AI models (pyannote.audio, Silero VAD, Demucs), it performs speaker diarization, speaker identification, voice activity detection, and noise reduction—all running locally on your hardware or accelerated with HuggingFace ZeroGPU.
## Features
### Three Powerful Workflows
1. **Speaker Separation**: Automatically separate multi-speaker conversations into individual speaker tracks
- Detects and isolates each speaker in an audio file
- Outputs separate M4A files for each speaker
- Ideal for interviews, podcasts, or conversations
2. **Speaker Extraction**: Extract a specific speaker using a reference voice clip
- Provide a reference clip of the target speaker
- Finds and extracts all segments matching that speaker
- High accuracy speaker identification (90%+)
3. **Voice Denoising**: Remove silence and background noise from audio
- Automatic voice activity detection (VAD)
- Background noise reduction
- Removes long silent gaps while preserving natural pauses
- Smooth segment transitions with crossfade
### Additional Features
- **Speech/Nonverbal Classification**: Extract only speech or capture emotional sounds separately
- **Batch Processing**: Process multiple files at once with progress tracking
- **Dual Interface**: Use via command-line (CLI) for automation or web interface (Gradio) for visual interaction
- **GPU Acceleration**: Supports HuggingFace ZeroGPU for 10-20x faster processing on Spaces
- **Local & Private**: Can run entirely on your computer - no cloud services, no data transmission
- **Flexible Deployment**: Works on CPU-only hardware or with GPU acceleration
## Requirements
- Python 3.11 or higher
- 4-8 core CPU recommended
- ~2GB RAM for processing
- ~600MB for AI model downloads (one-time)
- FFmpeg (for audio format conversion)
## Installation
### 1. Install FFmpeg
**macOS** (via Homebrew):
```bash
brew install ffmpeg
```
**Linux** (Ubuntu/Debian):
```bash
sudo apt-get update
sudo apt-get install ffmpeg
```
**Windows**:
Download from [ffmpeg.org](https://ffmpeg.org/download.html)
### 2. Install Voice Tools
```bash
# Clone the repository
git clone <repository-url>
cd voice-tools
# Create virtual environment
python3.11 -m venv .venv
source .venv/bin/activate # On Windows: .venv\Scripts\activate
# Install dependencies
pip install -e .
```
### 3. HuggingFace Authentication (Required)
Some AI models require HuggingFace authentication:
```bash
# Install HuggingFace CLI
pip install huggingface-hub
# Login (follow prompts)
huggingface-cli login
# Accept model licenses at:
# https://huggingface.co/pyannote/speaker-diarization-3.1
# https://huggingface.co/pyannote/embedding
```
## Quick Start
### Web Interface (Recommended for Beginners)
The easiest way to use Voice Tools is through the web interface:
```bash
voice-tools web
```
This opens a browser-based UI at http://localhost:7860 where you can:
- Upload your reference voice and audio files
- Configure extraction settings with sliders
- See real-time progress
- Download results as individual files or a ZIP
**Web Interface Options:**
```bash
# Run on different port
voice-tools web --port 8080
# Create public share link (accessible from other devices)
voice-tools web --share
# Custom host
voice-tools web --host 127.0.0.1 --port 7860
```
### CLI Usage
#### 1. Speaker Separation
**Separate speakers in a conversation:**
```bash
voice-tools separate conversation.m4a
```
**Custom output directory:**
```bash
voice-tools separate interview.m4a --output-dir ./speakers
```
**Specify speaker count:**
```bash
voice-tools separate podcast.m4a --min-speakers 2 --max-speakers 3
```
#### 2. Speaker Extraction
**Extract specific speaker using reference clip:**
```bash
voice-tools extract-speaker reference.m4a target.m4a
```
**Adjust matching sensitivity:**
```bash
voice-tools extract-speaker reference.m4a target.m4a \
--threshold 0.35 \
--min-confidence 0.25
```
**Save as separate segments instead of concatenated:**
```bash
voice-tools extract-speaker reference.m4a target.m4a \
--no-concatenate \
--output ./segments
```
#### 3. Voice Denoising
**Remove silence and background noise:**
```bash
voice-tools denoise noisy_audio.m4a
```
**Aggressive noise removal:**
```bash
voice-tools denoise noisy_audio.m4a \
--vad-threshold 0.7 \
--silence-threshold 1.0
```
**Custom output and format:**
```bash
voice-tools denoise noisy_audio.m4a \
--output clean_audio.wav \
--output-format wav
```
#### Legacy Voice Extraction
**Extract speech from single file:**
```bash
voice-tools extract reference.m4a input.m4a
```
**Extract from multiple files:**
```bash
voice-tools extract reference.m4a file1.m4a file2.m4a file3.m4a
```
**Process entire directory:**
```bash
voice-tools extract reference.m4a ./audio_files/
```
**Extract nonverbal sounds:**
```bash
voice-tools extract reference.m4a input.m4a --mode nonverbal
```
**Scan file for voice activity:**
```bash
voice-tools scan input.m4a
```
## HuggingFace Spaces Deployment
Voice Tools supports deployment to HuggingFace Spaces with GPU acceleration using ZeroGPU. This provides 10-20x faster processing compared to CPU-only execution.
### Prerequisites
1. **HuggingFace Account**: Sign up at [huggingface.co](https://huggingface.co/)
2. **HuggingFace Token**: Create a token at [huggingface.co/settings/tokens](https://huggingface.co/settings/tokens) with "read" access
3. **Model Access**: Accept the licenses for required models:
- [pyannote/speaker-diarization-3.1](https://huggingface.co/pyannote/speaker-diarization-3.1)
- [pyannote/embedding](https://huggingface.co/pyannote/embedding)
### Deployment Steps
1. **Fork this repository** to your GitHub account
2. **Create a new Space** at [huggingface.co/new-space](https://huggingface.co/new-space):
- Choose a name for your Space
- Select "Gradio" as the SDK
- Choose "ZeroGPU" as the hardware (or "CPU basic" for free tier)
- Make it Public or Private based on your preference
3. **Connect your GitHub repository**:
- In Space settings, go to "Files and versions"
- Click "Connect to GitHub"
- Select your forked repository
4. **Configure environment variables**:
- Go to Space settings → "Variables and secrets"
- Add a new secret:
- Name: `HF_TOKEN`
- Value: Your HuggingFace token (from prerequisites)
5. **Wait for deployment**: The Space will automatically build and deploy. This takes 5-10 minutes for the first deployment.
6. **Access your Space**: Once deployed, your Space will be available at `https://huggingface.co/spaces/YOUR_USERNAME/YOUR_SPACE_NAME`
### Configuration
The deployment is configured through these files:
- **`.space/README.md`**: Space metadata (title, emoji, SDK version, hardware)
- **`requirements.txt`**: Python dependencies
- **`Dockerfile`**: Custom Docker build for optimized layer caching
- **`app.py`**: Entry point that launches the Gradio interface
### GPU Acceleration
GPU acceleration is automatically enabled when running on ZeroGPU hardware:
- **Speaker Separation**: 90 seconds GPU duration per request
- **Speaker Extraction**: 60 seconds GPU duration per request
- **Voice Denoising**: 45 seconds GPU duration per request
The application automatically detects the ZeroGPU environment and applies the `@spaces.GPU()` decorator to inference functions. Models are loaded on CPU and moved to GPU only during processing for efficient resource usage.
### Troubleshooting Deployment
**Build fails with "No module named 'src.models'":**
- Ensure `.gitignore` uses `/models/` and `/lib/` (with leading slash) to avoid excluding `src/models/` and `src/lib/` directories
- Verify `src/models/` and `src/lib/` are committed to git
**Runtime error: "CUDA has been initialized before importing spaces":**
- Ensure `app.py` imports `spaces` before any PyTorch imports
- Check that service files use fallback decorator when spaces is not available
**Models not loading:**
- Verify `HF_TOKEN` secret is set correctly in Space settings
- Ensure you've accepted the model licenses in prerequisites
- Check Space logs for authentication errors
**Out of GPU memory:**
- Reduce audio file duration (split long files)
- Adjust GPU duration parameters in service decorators if needed
- Consider using CPU hardware tier for very long files
### Local Testing with ZeroGPU
To test ZeroGPU compatibility locally:
```bash
# Set environment variable to simulate Spaces environment
export SPACES_ZERO_GPU=1
# Install spaces package
pip install spaces>=0.28.3
# Run the app
python app.py
```
Note: GPU decorators will be applied but actual GPU allocation requires HuggingFace infrastructure.
## How It Works
1. **Voice Activity Detection**: Scans audio to find voice regions, skipping silence (saves 50% processing time)
2. **Speaker Identification**: Uses AI to match voice patterns against your reference clip
3. **Speech Classification**: Separates speech from nonverbal sounds using audio classification
4. **Quality Filtering**: Automatically filters out low-quality segments below threshold
5. **Extraction**: Saves only the target voice segments as clean audio files
6. **Optional Noise Removal**: Reduces background music and ambient noise
## Performance
Based on real-world testing with mostly inaudible audio files:
- **Single 45-minute file**: 4-6 minutes processing (with VAD optimization)
- **Batch of 13 files (9.5 hours)**: ~60-90 minutes total
- **Typical yield**: 5-10 minutes of usable audio per 45-minute file
- **Quality**: 90%+ voice identification accuracy, 60%+ noise reduction
## Output Format
- **Format**: M4A (AAC codec)
- **Sample Rate**: 48kHz (video standard)
- **Bit Rate**: 192kbps
- **Channels**: Mono
- **Compatible with**: Adobe Premiere, Final Cut Pro, DaVinci Resolve, most video generation tools
## Architecture
- **Models**: Open-source AI models from HuggingFace
- pyannote/speaker-diarization-3.1 (speaker identification)
- MIT/ast-finetuned-audioset (speech/nonverbal classification)
- Silero VAD v4.0 (voice activity detection)
- Demucs (music separation)
- **License**: All models use permissive licenses (MIT, Apache 2.0)
- **Processing**: Fully local on CPU - no cloud APIs
## Troubleshooting
**Models not downloading:**
- Ensure HuggingFace authentication is complete
- Check internet connection for first-time download
- Models cache in `./models/` directory
**Low extraction yield:**
- This is normal for mostly inaudible source files
- Check extraction statistics in output logs
- Try different reference clips for better voice matching
**Out of memory errors:**
- Process fewer files at once
- Close other applications
- Consider files with shorter duration
**FFmpeg not found:**
- Verify FFmpeg is installed: `ffmpeg -version`
- Add FFmpeg to system PATH
## Contributing
See [CONTRIBUTING.md](CONTRIBUTING.md) for development setup and guidelines.
## License
MIT License - see [LICENSE](LICENSE) for details.
## Acknowledgments
- [pyannote.audio](https://github.com/pyannote/pyannote-audio) for speaker diarization
- [Silero VAD](https://github.com/snakers4/silero-vad) for voice activity detection
- [Hugging Face](https://huggingface.co/) for model hosting
- [Gradio](https://gradio.app/) for web interface framework
|