Skip to content

The application uses SpeechRecognition, GoogleTranslator, and gTTS to convert spoken English or Tamil into the opposite language, display the translated text, and play the audio output.

Notifications You must be signed in to change notification settings

Sharan-Kumar-R/Talk2Translate

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

25 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸŽ™ English ↔ Tamil Speech Translator (Ollama LLM)

Python SpeechRecognition Ollama Llama 3.2 gTTS Pygame English-Tamil

A real-time speech translation application that converts spoken English to Tamil and vice versa, powered by Ollama's local LLM (Llama 3.2) for translation, with text-to-speech playback functionality.

Features

  • Speak in English or Tamil and get instant translation
  • Local LLM-powered translation using Ollama (Llama 3.2)
  • Automatic bidirectional translation (English ↔ Tamil)
  • Listen to the translated speech output
  • Save Translations - Store your translations to a local file
  • Clean, modern UI using CustomTkinter
  • Threaded processing for smooth performance
  • Privacy-focused - All translation happens locally

What's New - Ollama Integration

This version replaces cloud-based translation APIs with local LLM translation using Ollama:

  • 100% offline translation (after initial model download)
  • No API costs or rate limits
  • Enhanced privacy - your data never leaves your machine
  • Customizable - Easy to switch between different Ollama models
  • High-quality translations powered by Llama 3.2

πŸ“Έ Demo / Output

The application provides a user-friendly graphical interface for real-time voice translation:

Talk2Translate Interface

Prerequisites

Before running this application, ensure you have:

  • Python 3.7 or higher
  • A working microphone
  • Audio output device for playback
  • Ollama installed and running locally (see installation steps below)
  • Internet connection (only for initial Ollama model download and speech recognition)

Installation

Step 1: Install Ollama

Ollama is required for local LLM-based translation.

  1. Visit ollama.com and download the installer for your OS

  2. Install Ollama following the platform-specific instructions:

    • Windows: Run the installer
    • macOS: Drag to Applications folder
    • Linux: Follow the command line installation
  3. Verify Ollama installation:

ollama --version
  1. Pull the Llama 3.2 model (used by default):
ollama pull llama3.2:latest
  1. Start the Ollama server (if not already running):
ollama serve

Note: The Ollama server should be running at http://localhost:11434 (default). The application will connect to this endpoint.

Step 2: Clone the Repository

Option A: Using VS Code Terminal

  1. Open Visual Studio Code
  2. Open a new terminal (Terminal β†’ New Terminal or `Ctrl+Shift+``)
  3. Navigate to your desired directory:
cd path/to/your/desired/folder
  1. Clone the repository:
git clone https://github.com/Sharan-Kumar-R/Talk2Translate.git
  1. Open the project folder:
cd Talk2Translate
  1. Open the project in VS Code:
code .

Option B: Using VS Code Git Integration

  1. Open Visual Studio Code
  2. Press Ctrl+Shift+P (Windows/Linux) or Cmd+Shift+P (Mac)
  3. Type "Git: Clone" and select it
  4. Paste the repository URL: https://github.com/Sharan-Kumar-R/Talk2Translate.git
  5. Choose a folder location and click "Select Repository Location"
  6. Click "Open" when prompted

Step 3: Create a Virtual Environment (Recommended)

  1. In the VS Code terminal, create a virtual environment:
python -m venv venv
  1. Activate the virtual environment:
    • Windows:
venv\Scripts\activate
  • macOS/Linux:
source venv/bin/activate

Step 4: Install Python Dependencies

Install the required packages:

pip install -r requirements.txt

If you don't have a requirements.txt file, install packages individually:

pip install customtkinter SpeechRecognition gTTS pygame ollama

Step 5: Install PortAudio (Required for Microphone Input)

The SpeechRecognition library requires PortAudio for microphone functionality.

macOS:

brew install portaudio

Windows:

  1. Download the appropriate PyAudio wheel file from Unofficial Windows Binaries
  2. Install using pip:
pip install PyAudio-0.2.11-cp39-cp39-win_amd64.whl

Alternatively, install Microsoft C++ Build Tools if needed.

Linux (Debian/Ubuntu):

sudo apt-get install portaudio19-dev python3-pyaudio

Usage

1. Start Ollama Server (if not already running)

ollama serve

2. Run the Application

python Bilingual.py

3. Select Translation Mode

  • Choose "English β†’ Tamil" to speak in English
  • Choose "Tamil β†’ English" to speak in Tamil

4. Start Listening

  • Click the "🎧 Start Listening" button
  • Speak clearly into your microphone
  • Wait for the LLM translation to appear

5. Save Translations

  • Click "πŸ’Ύ Save Translation" to save the current translation
  • Translations are saved to translations.txt in the application directory

Configuration

You can customize the Ollama configuration by editing these variables in Bilingual.py:

OLLAMA_HOST = "http://localhost:11434"  # Ollama server address
OLLAMA_MODEL = "llama3.2:latest"        # Model to use for translation

Available Ollama Models for Translation

You can experiment with different models:

# Smaller, faster model
ollama pull llama3.2:1b

# Default model (balanced)
ollama pull llama3.2:latest

# Larger, more capable model
ollama pull llama3.1:8b

# Or other multilingual models
ollama pull mistral

Update the OLLAMA_MODEL variable in the code to switch models.

How It Works

  1. Speech Capture: The application listens to your microphone input
  2. Speech-to-Text: Converts your speech to text using Google Speech Recognition
  3. LLM Translation: Translates the text using local Ollama LLM (Llama 3.2)
  4. Text-to-Speech: Converts the translated text to speech using gTTS
  5. Playback: Plays the audio translation automatically

Project Structure

Talk2Translate/
β”‚
β”œβ”€β”€ Bilingual.py          # Main application file (uses google translator)
β”œβ”€β”€ Bilingualllm.py       # Main application file (uses local llm)
β”œβ”€β”€ Talk2Translate.png    # Demo image
β”œβ”€β”€ requirements.txt      # Python dependencies
β”œβ”€β”€ translations.txt      # Saved translations (auto-generated)
└── README.md             # This file

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests if applicable
  5. Submit a pull request

In case of any queries, please leave a message or contact me via the email provided in my profile.

⭐ Star this repository if you found it helpful!

About

The application uses SpeechRecognition, GoogleTranslator, and gTTS to convert spoken English or Tamil into the opposite language, display the translated text, and play the audio output.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages