This repository contains a Python script that automates the process of capturing on-screen text, translating it into French, and typing the translated text with proper accents. The script integrates optical character recognition (OCR), Google Translate API, and automation tools like PyAutoGUI.
- Text Capture: Extract text from a defined screen region using Tesseract OCR.
- French Translation: Translate captured text into French using the Google Translate API.
- Text Cleaning: Automatically remove unwanted characters using regex patterns.
- Keyboard Shortcuts: Automate application switching with Alt+Tab.
- Clipboard Integration: Paste translated text using Pyperclip.
- Tab Navigation: Simulate keypresses to navigate between input fields.
- Adjustable screen capture region.
- Configurable Tesseract OCR options for improved speed and accuracy.
git clone https://github.com/username/screen-translation-automation.git
cd screen-translation-automationInstall required libraries using pip:
pip install googletrans==4.0.0-rc1 pyautogui pytesseract pillow pyperclipEnsure Tesseract is installed and update the script with the correct path:
pytesseract.pytesseract.tesseract_cmd = r'C:\Program Files\Tesseract-OCR\tesseract.exe'-
Define the Screen Region: Update the
regionparameter incapture_and_read_text()to match your desired capture area:region = (100, 100, 1250, 400)
-
Run the Script: Launch the script to start automating the process:
python screen_translation.py
-
Switch Applications: Ensure the target application is active after the Alt+Tab automation.
-
Translation Output: The script:
- Captures text from the screen.
- Translates it into French.
- Types the translated text into the active application.
- Text Capture: A screenshot is taken of a predefined region on the screen.
- OCR Extraction: The captured image is processed using Tesseract to extract text.
- French Translation: The text is translated into French using Google Translate.
- Text Entry: The translated text is pasted into the active field using keyboard automation.
- Language Selection: Add support for multiple target languages.
- GUI Interface: Provide an interface for defining regions and customizing settings.
- Error Logging: Implement detailed error handling and logging for debugging.