A real-time translation web app built for healthcare communication, combining speech recognition, AI-powered translation, and text-to-speech to bridge language barriers between patients and medical staff.
- Speech-to-text — captures spoken input directly from the browser microphone
- Real-time translation — translates text via WebSocket communication with low latency
- Text-to-speech — converts the translated text back into spoken audio
- Medical-context aware translation — preserves medical terminology accuracy, cultural appropriateness, and formality (not just literal translation)
- Multi-language support — source and target language selection via dropdowns
This project explores two different translation backends, implemented on separate branches:
| Branch | Translation Engine | Notes |
|---|---|---|
master |
OpenAI API (gpt-3.5-turbo) |
Context-aware medical translation — understands terminology, tone, and cultural nuance. Requires a paid OpenAI subscription for unrestricted use. |
GoogletransAPI |
Google Translate API | Faster, free-tier friendly, but lacks the medical-context awareness of the LLM-based approach |
The OpenAI-powered branch represents the more advanced implementation — it doesn't just translate words, it adapts medical terminology and tone appropriately for clinical communication.
User speaks into microphone
↓
webkitSpeechRecognition converts speech → text
↓
Text + language codes sent via WebSocket (translate_text event)
↓
Flask backend receives request → calls OpenAI GPT-3.5-turbo
↓
AI translates with medical accuracy + cultural appropriateness
↓
translation_response event sent back to client
↓
Translated text displayed + converted to speech (SpeechSynthesisUtterance)
| Layer | Technology |
|---|---|
| Backend | Flask (Python) |
| Real-time communication | Flask-SocketIO |
| Translation Engine (main) | OpenAI API — gpt-3.5-turbo |
| Translation Engine (alt branch) | Google Translate API |
| Speech-to-Text | webkitSpeechRecognition (Web Speech API) |
| Text-to-Speech | SpeechSynthesisUtterance (Web Speech API) |
| Frontend | HTML, CSS, JavaScript |
| Environment Config | python-dotenv |
| Deployment | Vercel |
healthcare-translation-app/
│
├── app.py # Flask + Socket.IO backend, OpenAI integration
├── requirements.txt # Python dependencies
├── .env # API keys (OPENAI_API_KEY, SECRET_KEY) — gitignored
├── vercel.json # Vercel deployment configuration
│
├── static/
│ ├── js/
│ │ ├── translation.js # WebSocket translation requests + UI state handling
│ │ └── speech.js # Speech-to-text & text-to-speech logic
│ └── css/
│ └── style.css # UI styling
│
└── templates/
└── index.html # Main UI: language selectors, record/translate/speak buttons
Backend — app.py
- Initializes Flask, Socket.IO, and environment variables
- Calls OpenAI's
gpt-3.5-turbofor medically accurate, context-aware translation - Serves the front-end via
/route - Handles real-time translation requests through the
translate_textWebSocket event - CORS configured to prevent unauthorized cross-origin requests
translation.js
- Sends translation requests over WebSocket
- Listens for
translation_responseandtranslation_errorevents - Formats translated text and manages UI state (loading spinners, error messages)
speech.js
- Captures spoken input via
webkitSpeechRecognition - Converts translated text to speech via
SpeechSynthesisUtterance
- API keys stored securely via
.env, excluded from version control via.gitignore - CORS configured for Socket.IO to prevent unauthorized cross-origin communication
- Backend input validation (e.g. rejecting empty text) to prevent abuse
- Graceful error handling for translation/connection failures
⚠️ Rate limiting recommended as a future improvement to protect the OpenAI API from excessive requests
- Python 3.x
- An OpenAI API key (paid subscription recommended — the free trial tier is rate-limited and not suitable for consistent use)
-
Clone the repository
git clone https://github.com/sheikhalyan/Health_Care.git cd HealthCare -
Create a virtual environment and install dependencies
python -m venv venv source venv/bin/activate # Windows: venv\Scripts\activate pip install -r requirements.txt
-
Create a
.envfile in the root directoryOPENAI_API_KEY=your_openai_api_key_here SECRET_KEY=your_flask_secret_key_here -
Run the app
python app.py
-
Open
http://localhost:5000in your browser
To try the Google Translate API implementation instead of OpenAI:
git checkout GoogletransAPIThis branch swaps the OpenAI translation call for the Google Translate API — useful for comparing cost, latency, and translation quality between an LLM-based approach and a traditional translation API.
This is a prototype built for demonstration and learning purposes. It is not a certified medical communication tool and should not be relied upon for critical clinical interactions without further validation and professional medical review.
Sheikh Alyan — Full-Stack Developer