Spaces:
Running
Running
File size: 7,438 Bytes
29716f5 4756c56 |
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 |
---
title: ClearSpeech API
emoji: ποΈ
colorFrom: blue
colorTo: purple
sdk: docker
pinned: false
license: mit
---
# ποΈ ClearSpeech
**AI-Powered Speech Enhancement & Transcription System**
ClearSpeech uses a custom U-Net deep learning model to remove background noise from audio, then transcribes the enhanced audio using OpenAI's Whisper. Perfect for cleaning up voice recordings, meeting audio, podcasts, or any noisy speech.
**π Live Website (will be updated)**: https://clearspeech.yourdomain.com
## π Features
- π§Ή **AI-Powered Noise Reduction**: Custom U-Net model trained to remove background noise
- π **Automatic Transcription**: Whisper integration for accurate speech-to-text
- β‘ **Fast Processing**: Optimized pipeline with GPU support
- π **REST API**: Easy-to-use FastAPI backend
- π― **High Quality**: Val loss of 0.031
- π§ **Flexible**: Enhancement-only, transcription-only, or both
## π Table of Contents
- Installation
- Quick Start
- API Documentation
- Project Structure
- Contributing
## π Installation
### Prerequisites
- Python 3.8+
- pip
- Optional CUDA GPU
### Step 1: Clone Repository
```
git clone https://github.com/yourusername/ClearSpeech.git
cd ClearSpeech
```
### Step 2: Create Virtual Environment
```
# Create environment
python3.10 -m venv venv
# Activate (macOS/Linux)
source venv/bin/activate
# Activate (Windows)
venv\Scripts\activate
```
### Step 3: Install Dependencies
```
# Install dependencies
pip install -r requirements.txt
```
### Step 4: Download Pretrained Model
```
# Download model
python -c "
from huggingface_hub import hf_hub_download
hf_hub_download(
repo_id='thecodeworm/clearspeech-unet',
filename='best_model.pt',
local_dir='enhancement_model/checkpoints/'
)
"
```
### Step 5: Generate Noisy Samples
1. Make your own WAV sample
2. Run the generate_noisy_samples.py file on the sample to make the audio noisier to test the model
```
# Generate all noise types at multiple SNR levvels
python generate_noisy_samples.py \
--input my_clean_voice.wav \
--output test_samples/
```
## β‘ Quick Start
### Method 1: Using the API (Recommended)
**Start the server:**
```
python -m backend.app
```
Server starts at `http://localhost:8000`
**Start the server:**
```
cd frontend
python -m http.server 3000
```
Frontend starts at `http://localhost:3000`
**Process audio:**
```
# Full pipeline (enhance + transcribe)
curl -X POST "http://localhost:8000/process" \
-F "file=@your_audio.wav" \
| jq .
# Enhance only
curl -X POST "http://localhost:8000/enhance" \
-F "file=@your_audio.wav" \
-o enhanced_output.wav
# Transcribe only
curl -X POST "http://localhost:8000/transcribe" \
-F "file=@your_audio.wav" \
-F "enhance=true" \
| jq .
```
**Method 2: Using Python**
```
from backend.inference_pipeline import EnhancementPipeline
# Initialize pipeline
pipeline = EnhancementPipeline(
cnn_checkpoint_path="enhancement_model/checkpoints/best_model.pt",
whisper_model_name="base",
device="cpu" # or "cuda" or "mps"
)
# Process audio
result = pipeline.process("path/to/noisy_audio.wav")
print(f"Transcript: {result['transcript']}")
print(f"Duration: {result['duration']:.2f}s")
# Save enhanced audio
import soundfile as sf
sf.write("enhanced.wav", result['enhanced_audio'], result['sample_rate'])
```
**Method 3: Command Line**
```
# Enhance audio file
python enhancement_model/infer.py \
--checkpoint enhancement_model/checkpoints/best_model.pt \
--input noisy_audio.wav \
--output enhanced_audio.wav \
--comparison # Creates stereo comparison file
```
## π API Documentation
### Interactive Docs
Once the server is running, visit:
- **Swagger UI**: [http://localhost:8000/docs](http://localhost:8000/docs)
- **ReDoc**: [http://localhost:8000/redoc](http://localhost:8000/redoc)
### Endpoints
#### `POST /process`
Process audio with enhancement and transcription.
**Request:**
```curl -X POST "http://localhost:8000/process" \
-F "file=@audio.wav" \
-F "language=en" \
-F "skip_enhancement=false"
```
**Response:**
```
{
"success": true,
"transcript": "Transcribed text here",
"duration": 3.5,
"language": "en",
"enhanced_audio_url": "/download/enhanced_123.wav",
"segments": [...],
"processing_time": 2.3
}
```
#### `POST /enhance`
Enhance audio only (no transcription).
**Request:**
```
curl -X POST "http://localhost:8000/enhance" \
-F "file=@audio.wav" \
-o enhanced.wav
```
**Response:** Enhanced audio file (WAV)
#### `POST /transcribe`
Transcribe audio with optional enhancement.
**Request:**
```
curl -X POST "http://localhost:8000/transcribe" \
-F "file=@audio.wav" \
-F "language=en" \
-F "enhance=true"
```
**Response:**
```
{
"success": true,
"transcript": "Transcribed text",
"duration": 3.5,
"language": "en",
"segments": [...]
}
```
#### `GET /download/{filename}`
Download enhanced audio file.
#### `GET /health`
Health check endpoint.
## π Project Structure
```
ClearSpeech/
βββ backend/ # FastAPI backend
β βββ app.py # Main API server
β βββ inference_pipeline.py # Processing pipeline
β βββ requirements.txt
βββ enhancement_model/ # U-Net model
β βββ model.py # U-Net architecture
β βββ dataset.py # PyTorch dataset
β βββ train.py # Training script
β βββ infer.py # Inference script
β βββ checkpoints/ # Trained models
β β βββ best_model.pt
β βββ requirements.txt
βββ data/ # Training/test data
β βββ audio_clean/ # Clean audio
β βββ audio_raw/ # Noisy audio
β βββ metadata/
β β βββ metadata.json # Dataset metadata
β βββ spectrograms/ # Mel-spectrograms
β βββ clean/
β βββ noisy/
βββ frontend/ # Web interface (optional)
β βββ index.html
β βββ script.js
βββ tests/ # Test files
β βββ test_backend.py
βββ README.md
βββ requirements.txt
```
## π€ Contributing
We welcome contributions! Here's how:
1. **Fork the repository**
2. **Create a feature branch**: `git checkout -b feature/amazing-feature`
3. **Commit changes**: `git commit -m 'Add amazing feature'`
4. **Push to branch**: `git push origin feature/amazing-feature`
5. **Open a Pull Request**
**Development Setup**
```
# Install dev dependencies
pip install -r requirements-dev.txt
# Run tests before committing
python -m pytest tests/
# Format code
black backend/ enhancement_model/
```
## π Acknowledgments
- **U-Net Architecture**: Inspired by [Ronneberger et al.](https://arxiv.org/abs/1505.04597)
- **Whisper**: [OpenAI Whisper](https://github.com/openai/whisper)
- **Training Data**: [LibriSpeech](http://www.openslr.org/12/), [MS-SNSD](https://github.com/microsoft/MS-SNSD)
## π§ Contact
**Project Maintainers**: Aditya Chanda, Josh Pal, Advik Kumar Singh
**Project Link**: [https://github.com/thecodeworm/ClearSpeech](https://github.com/thecodeworm/ClearSpeech)
## β Show Your Support
Give a βοΈ if this project helped you!
----------
**Built with β€οΈ using PyTorch and FastAPI**
|