A powerful Streamlit-based application that translates text using Google's Generative AI and converts translations to speech using Google Text-to-Speech (gTTS).
- Multi-format Input Support: Type text or upload files (TXT, PDF, DOCX, CSV, XLSX, XLS)
- AI-Powered Translation: Uses Google's Gemini AI models for accurate translations
- Text-to-Speech: Convert translations to audio with download capability
- Multi Languages: Support for major world languages including English, Spanish, French, German, Chinese, Hindi, Arabic, and more
- File Processing: Extract and translate text from various document formats
- Modular Architecture: Clean, maintainable code structure
- Error Handling: Robust error handling with user-friendly messages
git clone <repository-url>
cd project# Create virtual environment (recommended)
python -m venv myenv
source myenv/bin/activate # On Windows: myenv\Scripts\activate
# Install required packages
pip install -r requirements.txtCreate a .env file in the project root:
# Google Generative AI API Key
GOOGLE_API_KEY=your_google_api_key_here
# Google Generative AI Model (optional)
GENAI_MODEL=gemini-2.0-flash- Go to Google AI Studio
- Click "Create API Key"
- Copy the generated key
- Paste it in your
.envfile
streamlit run translate/translate_app.pyproject/
βββ .env # Environment variables (keep secret!)
βββ .gitignore # Git ignore file
βββ requirements.txt # Python dependencies
βββ README.md # This file
βββ myenv/ # Virtual environment
βββ translate/ # Main application package
βββ __init__.py # Package initialization
βββ translate_app.py # Main Streamlit application
βββ translation_service.py # Google AI translation logic
βββ audio_service.py # Text-to-speech functionality
βββ file_processors.py # File extraction utilities
βββ ui_components.py # UI rendering components
streamlit>=1.20.0 # Web application framework
google-generativeai>=0.2.0 # Google AI integration
python-dotenv>=1.0.0 # Environment variable management
gtts>=2.3.0 # Google Text-to-SpeechPyPDF2>=3.0.0 # PDF text extraction
python-docx>=0.8.11 # Word document processing
pandas>=1.5.0 # Excel/CSV processing
openpyxl>=3.0.0 # Excel file support
xlrd>=2.0.0 # Legacy Excel supportlangchain>=0.0.208 # AI workflow framework
chromadb>=0.3.23 # Vector database
watchdog>=3.0.0 # File monitoring- Select "βοΈ Type Text" option
- Enter your text in the text area
- Choose target language
- Click "π Start Processing"
- Select "π Upload File" option
- Upload supported file formats:
- TXT: Plain text files
- PDF: Portable Document Format
- DOCX: Microsoft Word documents
- CSV: Comma-separated values
- XLSX/XLS: Excel spreadsheets
- Preview extracted text
- Choose target language
- Click "π Start Processing"
- After successful translation
- Translated text is Converted to Speech
- Listen to generated audio
- Download audio file (MP3 format)
To add support for more languages, https://en.wikipedia.org/wiki/List_of_ISO_639_language_codes
# Required
GOOGLE_API_KEY=your_api_key_here
# Optional
GENAI_MODEL=gemini-2.0-flash # Default model to useβ GOOGLE_API_KEY not found in environment variables
Solution:
- Ensure
.envfile exists in project root - Check API key is correctly formatted
- Regenerate API key if needed
Error: 429 You exceeded your current quota
Solution:
- Check usage limits in Google AI Studio
- Wait for quota reset (usually daily)
- Upgrade your Google AI plan
- Use shorter text inputs
Error: 404 models/gemini-pro is not found
Solution:
- Try different model name in
.env - Check model availability in your region
- Update
google-generativeaipackage
Solution:
- Ensure file format is supported
- Check file isn't corrupted
- Try smaller file sizes
- Verify file encoding (UTF-8 recommended)
Run the debug script to test your API configuration:
python debug_api.py- Never commit
.envfile to version control - Keep API keys secure and regenerate if compromised
- Use environment variables for sensitive data
- Monitor API usage to prevent unexpected charges
Ensure .gitignore includes:
# Environment variables
.env
# Python
__pycache__/
*.pyc
myenv/
# Streamlit
.streamlit/- Add extraction function in
file_processors.py - Update
process_uploaded_file()function - Add file type to upload widget in
ui_components.py - Update requirements.txt if new dependencies needed
- Add language to
languagesdictionary inui_components.py - Ensure gTTS supports the language code
- Test translation and TTS functionality
- Modify
ui_components.pyfor layout changes - Update CSS in main app for styling
- Add new sections as needed
This project is open source. Please check the license file for details.
- Fork the repository
- Create a feature branch
- Make your changes
- Test thoroughly
- Submit a pull request
If you encounter issues:
- Check the troubleshooting section
- Run the debug script
- Check your API quota and billing
- Ensure all dependencies are installed
- Verify file formats are supported
- Initial release
- Basic text translation
- File upload support
- Text-to-speech functionality
- Modular architecture
Made with β€οΈ using Streamlit and Google AI