-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathOCR.py
27 lines (27 loc) · 765 Bytes
/
OCR.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import cv2
import sys
import pytesseract
from gtts import gTTS
import time
import os
from playsound import playsound
import os.path
from os import path
pytesseract.pytesseract.tesseract_cmd=r'Path To The Executable Tesseract File.'
myfile=open("test.txt","w")
myfile.close()
img=input("\nEnter The Path To The Image.\n")
frame = cv2.imread(img)
cv2.imshow('Picture', frame)
sctext=pytesseract.image_to_string(frame)
with open('test.txt', mode='a') as file:
file.write(sctext)
language='en'
if((os.stat("test.txt").st_size == 0)==False):
myfile=open("test.txt","r")
contents=myfile.read()
myfile.close()
obj=gTTS(text=contents, lang=language, slow=False)
obj.save("sample.mp3")
if(path.exists('sample.mp3')==True):
playsound('sample.mp3')