A comprehensive FastAPI-based real-time audio processing system designed for live customer service call analysis. This system provides real-time speaker diarization, transcription, sentiment analysis, and emotion recognition with WebSocket streaming capabilities.
- Real-time microphone input capture with optimized audio buffers
- Voice Activity Detection (VAD) for efficient processing
- Multi-channel audio support with noise reduction
- Adaptive audio quality based on connection
- Advanced speaker diarization (Agent vs Customer identification)
- Speaker embedding and clustering
- Real-time speaker switching detection
- Voice characteristic analysis
- Live speech-to-text with Faster-Whisper models
- Multi-language support and automatic language detection
- Real-time transcription streaming
- Confidence scoring and error correction
- Dual-mode sentiment analysis: Text-based and Voice-based
- Real-time emotion recognition from speech patterns
- Voice feature extraction (pitch, energy, speaking rate, tone)
- Conversation flow analysis and emotional trajectory tracking
- WebSocket-based real-time data streaming
- Angular frontend integration
- RESTful API endpoints for control and monitoring
- Real-time dashboard with live updates
AudioPipelineTreatment/
βββ π capture/ # Audio capture and processing
β βββ audio_capture.py # Main audio capture logic
β βββ __init__.py
βββ π diarization/ # Speaker diarization
β βββ speaker_diarization.py # Speaker identification
β βββ test_diarization.py # Diarization tests
β βββ newdir.py
βββ π transcription/ # Speech-to-text
β βββ speech_to_text.py # Whisper-based transcription
βββ π sentiment/ # Sentiment analysis modules
β βββ SentimentFromTrans.py # Text-based sentiment
β βββ VoiceEmotionRecognizer.py # Voice emotion analysis
β βββ VoiceSentiment.py # Voice sentiment analysis
β βββ TranscriptSentiment.py # Transcript processing
βββ π tests/ # Comprehensive test suite
β βββ test_pipeline.py # Pipeline integration tests
β βββ test_realtime_sentiment.py
β βββ testdiarizatio.py
βββ π models/ # Pre-trained model storage
β βββ wav2vec2-lg-xlsr-en-speech-emotion-recognition/
β βββ faster-whisper-base.en/
βββ π logs/ # Application logs
βββ π tmp/ # Temporary processing files
βββ π main.py # FastAPI application entry
βββ π enhanced_web_realtime_pipeline.py # Core pipeline
βββ π RealTimePipelineMic.py # Microphone pipeline
βββ π RealTimeWavPipeline.py # WAV file pipeline
βββ π requirements.txt # Python dependencies
βββ π³ dockerfile # Docker configuration
βββ π PROCESS_FLOW_DOCUMENTATION.md # Detailed technical docs
- Python 3.8+ (3.12 recommended)
- Working microphone for real-time audio capture
- NVIDIA GPU (optional, for accelerated processing)
- 4GB+ RAM for model loading
- Internet connection (for initial model downloads)
- Clone and Navigate
git clone <repository-url>
cd AudioPipelineTreatment- Create Virtual Environment
python -m venv venv
venv\Scripts\activate- Install Dependencies
pip install -r requirements.txt-
Download Models (Automatic on first run)
- Faster-Whisper models will download automatically
- Voice emotion models will be cached locally
- Speaker diarization models will be loaded from HuggingFace
-
Run the Application
uvicorn main:app --reload --host 0.0.0.0 --port 8000- API Documentation: http://localhost:8000/docs
- WebSocket Endpoint: ws://localhost:8000/ws
- Health Check: http://localhost:8000/health
| Method | Endpoint | Description |
|---|---|---|
GET |
/ |
Root endpoint with welcome message |
GET |
/health |
System health and status check |
POST |
/upload-audio |
Upload audio file for batch processing |
WS |
/ws |
WebSocket for real-time audio streaming |
- Connect to
ws://localhost:8000/ws - Send audio data as base64-encoded chunks
- Receive real-time analysis results
{
"type": "audio",
"data": "base64-encoded-audio-chunk",
"sampleRate": 16000,
"channels": 1
}{
"timestamp": "2025-08-20T12:34:56",
"speaker": "SPEAKER_00",
"transcription": "Hello, how can I help you today?",
"sentiment": {
"text_sentiment": "POSITIVE",
"text_confidence": 0.92,
"voice_emotion": "HAPPY",
"voice_confidence": 0.87,
"combined_sentiment": "POSITIVE"
},
"voice_features": {
"pitch": 185.23,
"energy": 0.12,
"speaking_rate": 0.08,
"tone_stability": 0.76
},
"speaker_info": {
"speaker_id": "SPEAKER_00",
"speaker_type": "agent",
"confidence": 0.94
}
}pytest tests/ -v# Test real-time sentiment analysis
pytest tests/test_realtime_sentiment.py -v
# Test pipeline integration
pytest tests/test_pipeline.py -v
# Test speaker diarization
pytest tests/testdiarizatio.py -v# Test audio capture directly
python AudioCaptureTester.py
# Test microphone pipeline
python RealTimePipelineMic.py
# Test WAV file processing
python RealTimeWavPipeline.pyπ 12:01:23 | π€ SPEAKER_00 | "Hello, how can I help you today?"
π [12:01:23] SENTIMENT: POSITIVE (confidence=0.92)
π Text: POSITIVE | π΅ Voice: HAPPY
ποΈ Voice Features - Pitch: 185.23Hz, Energy: 0.12, Rate: 2.1 words/sec
π 12:01:28 | π€ SPEAKER_01 | "I'm having trouble with my account."
π [12:01:28] SENTIMENT: FRUSTRATED (confidence=0.78)
π Text: NEUTRAL | π΅ Voice: FRUSTRATED
ποΈ Voice Features - Pitch: 165.45Hz, Energy: 0.18, Rate: 1.8 words/sec
{
"session_id": "sess_1724150456",
"timestamp": "12:01:23",
"analysis": {
"speaker": {
"id": "SPEAKER_00",
"type": "agent",
"confidence": 0.94
},
"transcription": {
"text": "Hello, how can I help you today?",
"confidence": 0.96,
"language": "en"
},
"sentiment": {
"overall": "POSITIVE",
"text_based": "POSITIVE",
"voice_based": "HAPPY",
"confidence": 0.92
},
"emotions": {
"primary": "HAPPY",
"secondary": "CONFIDENT",
"arousal": 0.7,
"valence": 0.8
},
"voice_analytics": {
"pitch_hz": 185.23,
"energy_db": -12.4,
"speaking_rate_wps": 2.1,
"pause_ratio": 0.15,
"tone_stability": 0.76
}
}
}# Model Configuration
WHISPER_MODEL_SIZE=base.en # tiny, base, small, medium, large
EMOTION_MODEL_PATH=./models/ # Custom emotion model path
ENABLE_GPU=true # Enable GPU acceleration
# Audio Settings
SAMPLE_RATE=16000 # Audio sample rate
BUFFER_SIZE=1024 # Audio buffer size
VAD_THRESHOLD=0.5 # Voice activity detection threshold
# API Settings
HOST=0.0.0.0 # API host
PORT=8000 # API port
DEBUG=false # Debug mode- Use GPU acceleration when available
- Adjust
BUFFER_SIZEbased on your hardware - Consider smaller Whisper models for faster processing
- Enable VAD to process only speech segments
- Use larger Whisper models (medium/large)
- Increase speaker diarization sensitivity
- Enable emotion model ensembling
# Build the container
docker build -t audio-pipeline .
# Run with GPU support
docker run --gpus all -p 8000:8000 audio-pipeline
# Run CPU-only
docker run -p 8000:8000 audio-pipelineversion: '3.8'
services:
audio-pipeline:
build: .
ports:
- "8000:8000"
environment:
- ENABLE_GPU=true
deploy:
resources:
reservations:
devices:
- driver: nvidia
count: 1
capabilities: [gpu]- FastAPI - Modern, fast web framework for APIs
- WebSockets - Real-time bidirectional communication
- PyTorch - Deep learning framework for ML models
- Faster-Whisper - Optimized speech recognition
- PyAnnote.Audio - Speaker diarization and audio analysis
- NumPy & SciPy - Numerical computing and signal processing
- Wav2Vec2-XLS-R - Voice emotion recognition
- Faster-Whisper-Base/Small - Speech-to-text transcription
- PyAnnote Speaker Diarization - Speaker identification
- Custom Sentiment Models - Text and voice sentiment analysis
- PyAudio - Real-time audio I/O
- LibROSA - Audio feature extraction
- TorchAudio - Audio processing with PyTorch
- Voice Activity Detection - Efficient audio segmentation
# Check microphone permissions
# Verify audio device in Device Manager
# Test with: python AudioCaptureTester.py# Check internet connection
# Clear cache: rm -rf ~/.cache/huggingface/
# Manual download: huggingface-cli download Systran/faster-whisper-base.en# Verify server is running: curl http://localhost:8000/health
# Check firewall settings
# Ensure port 8000 is available# Reduce model size in config
# Enable GPU acceleration
# Adjust buffer sizes
# Close other applications- Use
tinyorbaseWhisper models - Reduce audio buffer size
- Enable GPU processing
- Optimize VAD thresholds
- Use
mediumorlargeWhisper models - Increase speaker diarization sensitivity
- Enable emotion model ensembling
- Use higher quality audio input
# Enable detailed logging
export DEBUG=true
python main.py
# View logs
tail -f pipeline.log- PROCESS_FLOW_DOCUMENTATION.md - Detailed technical implementation
- API Documentation - Interactive Swagger UI
- Model Documentation - ML model specifications
- Testing Guide - Comprehensive testing procedures
- Fork the repository
- Create a feature branch:
git checkout -b feature/amazing-feature - Install development dependencies:
pip install -r requirements-dev.txt - Run tests:
pytest - Commit changes:
git commit -m 'Add amazing feature' - Push to branch:
git push origin feature/amazing-feature - Open a Pull Request
- Follow PEP 8 for Python code style
- Add docstrings to all functions and classes
- Write unit tests for new features
- Update documentation for API changes
This project is licensed under the MIT License - see the LICENSE file for details.
- Issues: GitHub Issues
- Discussions: GitHub Discussions
- Documentation: Process Flow Documentation
- Minimum: Python 3.8, 4GB RAM, Intel i5 or equivalent
- Recommended: Python 3.12, 8GB RAM, NVIDIA GPU, Intel i7 or equivalent
- Operating Systems: Windows 10+, macOS 10.15+, Ubuntu 18.04+
π Ready to get started? Run uvicorn main:app --reload and visit http://localhost:8000/docs to explore the API!
π― Need real-time analysis? Connect to ws://localhost:8000/ws and start streaming audio data!
π Want to see it in action? Check out the Process Flow Documentation for detailed examples!