Ocr now copies detected text to the clipboard.
This commit is contained in:
parent
65e6dcf980
commit
fdc2fdc41d
@ -23,6 +23,7 @@ import time
|
||||
import subprocess
|
||||
from PIL import Image, ImageOps
|
||||
import pytesseract
|
||||
import pyperclip
|
||||
|
||||
def capture_screen(max_retries=3, initial_delay=0.2):
|
||||
"""
|
||||
@ -102,6 +103,22 @@ def perform_ocr(img, lang='eng'):
|
||||
|
||||
return text
|
||||
|
||||
def copy_to_clipboard(text):
|
||||
"""Copy text to clipboard using pyperclip"""
|
||||
try:
|
||||
# Filter out empty lines and clean up the text
|
||||
lines = [line.strip() for line in text.split('\n') if line.strip()]
|
||||
cleaned_text = '\n'.join(lines) # Preserve line breaks for clipboard
|
||||
|
||||
if cleaned_text:
|
||||
pyperclip.copy(cleaned_text)
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
except Exception as e:
|
||||
print(f"Error copying to clipboard: {e}")
|
||||
return False
|
||||
|
||||
def speak_text(text):
|
||||
"""Speak the text using speech-dispatcher"""
|
||||
# Filter out empty lines and clean up the text
|
||||
@ -131,9 +148,12 @@ def main():
|
||||
# Perform OCR
|
||||
text = perform_ocr(processed_img)
|
||||
|
||||
# Copy to clipboard
|
||||
clipboard_success = copy_to_clipboard(text)
|
||||
|
||||
# Speak the results
|
||||
speak_text(text)
|
||||
|
||||
|
||||
except Exception as e:
|
||||
# Let the user know something went wrong
|
||||
error_msg = f"Error during OCR: {str(e)}"
|
||||
|
Loading…
x
Reference in New Issue
Block a user