- Add token bucket rate limiter with sliding window algorithm - Implement per-endpoint configurable rate limits - Add automatic IP blocking for excessive requests - Implement global request limits and concurrent request throttling - Add request size validation for all endpoints - Create admin endpoints for rate limit management - Add rate limit headers to responses - Implement cleanup thread for old rate limit buckets - Create detailed rate limiting documentation Rate limits: - Transcription: 10/min, 100/hour, max 10MB - Translation: 20/min, 300/hour, max 100KB - Streaming: 10/min, 150/hour, max 100KB - TTS: 15/min, 200/hour, max 50KB - Global: 1000/min, 10000/hour, 50 concurrent Security features: - Automatic temporary IP blocking (1 hour) for abuse - Manual IP blocking via admin endpoint - Request size validation to prevent large payload attacks - Burst control to limit sudden traffic spikes 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
120 lines
3.1 KiB
Markdown
120 lines
3.1 KiB
Markdown
# Voice Language Translator
|
|
|
|
A mobile-friendly web application that translates spoken language between multiple languages using:
|
|
- Gemma 3 open-source LLM via Ollama for translation
|
|
- OpenAI Whisper for speech-to-text
|
|
- OpenAI Edge TTS for text-to-speech
|
|
|
|
## Supported Languages
|
|
|
|
- Arabic
|
|
- Armenian
|
|
- Azerbaijani
|
|
- English
|
|
- French
|
|
- Georgian
|
|
- Kazakh
|
|
- Mandarin
|
|
- Farsi
|
|
- Portuguese
|
|
- Russian
|
|
- Spanish
|
|
- Turkish
|
|
- Uzbek
|
|
|
|
## Setup Instructions
|
|
|
|
1. Install the required Python packages:
|
|
```
|
|
pip install -r requirements.txt
|
|
```
|
|
|
|
2. Configure environment variables:
|
|
```bash
|
|
# Copy the example environment file
|
|
cp .env.example .env
|
|
|
|
# Edit with your actual values
|
|
nano .env
|
|
|
|
# Or set directly:
|
|
export TTS_API_KEY="your-tts-api-key"
|
|
export SECRET_KEY="your-secret-key"
|
|
```
|
|
|
|
**⚠️ Security Note**: Never commit API keys or secrets to version control. See [SECURITY.md](SECURITY.md) for details.
|
|
|
|
3. Make sure you have Ollama installed and the Gemma 3 model loaded:
|
|
```
|
|
ollama pull gemma3
|
|
```
|
|
|
|
4. Ensure your OpenAI Edge TTS server is running on port 5050.
|
|
|
|
5. Run the application:
|
|
```
|
|
python app.py
|
|
```
|
|
|
|
6. Open your browser and navigate to:
|
|
```
|
|
http://localhost:8000
|
|
```
|
|
|
|
## Usage
|
|
|
|
1. Select your source language from the dropdown menu
|
|
2. Press the microphone button and speak
|
|
3. Press the button again to stop recording
|
|
4. Wait for the transcription to complete
|
|
5. Select your target language
|
|
6. Press the "Translate" button
|
|
7. Use the play buttons to hear the original or translated text
|
|
|
|
## Technical Details
|
|
|
|
- The app uses Flask for the web server
|
|
- Audio is processed client-side using the MediaRecorder API
|
|
- Whisper for speech recognition with language hints
|
|
- Ollama provides access to the Gemma 3 model for translation
|
|
- OpenAI Edge TTS delivers natural-sounding speech output
|
|
|
|
## CORS Configuration
|
|
|
|
The application supports Cross-Origin Resource Sharing (CORS) for secure cross-origin usage. See [CORS_CONFIG.md](CORS_CONFIG.md) for detailed configuration instructions.
|
|
|
|
Quick setup:
|
|
```bash
|
|
# Development (allow all origins)
|
|
export CORS_ORIGINS="*"
|
|
|
|
# Production (restrict to specific domains)
|
|
export CORS_ORIGINS="https://yourdomain.com,https://app.yourdomain.com"
|
|
export ADMIN_CORS_ORIGINS="https://admin.yourdomain.com"
|
|
```
|
|
|
|
## Connection Retry & Offline Support
|
|
|
|
Talk2Me handles network interruptions gracefully with automatic retry logic:
|
|
- Automatic request queuing during connection loss
|
|
- Exponential backoff retry with configurable parameters
|
|
- Visual connection status indicators
|
|
- Priority-based request processing
|
|
|
|
See [CONNECTION_RETRY.md](CONNECTION_RETRY.md) for detailed documentation.
|
|
|
|
## Rate Limiting
|
|
|
|
Comprehensive rate limiting protects against DoS attacks and resource exhaustion:
|
|
- Token bucket algorithm with sliding window
|
|
- Per-endpoint configurable limits
|
|
- Automatic IP blocking for abusive clients
|
|
- Global request limits and concurrent request throttling
|
|
- Request size validation
|
|
|
|
See [RATE_LIMITING.md](RATE_LIMITING.md) for detailed documentation.
|
|
|
|
## Mobile Support
|
|
|
|
The interface is fully responsive and designed to work well on mobile devices.
|