OCR-Translator / ObjCharRec.py
Sarath0x8f's picture
Update ObjCharRec.py
582935f verified
from paddleocr import PaddleOCR
import translate_speak
import datetime
def ocr_with_paddle(img):
"""
Paddle OCR
"""
try:
finaltext = ''
ocr = PaddleOCR(lang='en', use_angle_cls=True, show_log=False)
result = ocr.ocr(img)
if result[0] == None:
finaltext = "Text not found in the given Image. Try with another Image"
else:
for i in range(len(result[0])):
text = result[0][i][1][0]
finaltext += ' ' + text
# with open("Request.txt", 'a', encoding="utf-8") as f:
# f.write(f"{datetime.datetime.now()}: {finaltext}\n")
print(f"\n{datetime.datetime.now()}: {finaltext}\n")
audio_path = translate_speak.audio_streaming(txt=finaltext, to=1)
return finaltext, audio_path
except Exception as e:
return f"An error occurred. Please upload image {e}", translate_speak.audio_streaming(txt="An error occurred. Please upload image", to=1)
if __name__ == "__main__":
print(ocr_with_paddle('Images/download.jpeg'))