File size: 890 Bytes
c847906
d69917c
c847906
d69917c
 
 
 
 
 
 
 
 
 
 
 
c847906
 
 
 
 
 
d69917c
 
c847906
d69917c
c847906
 
d69917c
 
 
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
28
29
30
import os

from paddleocr import PaddleOCR
import translate_speak


def ocr_with_paddle(img):
    """

    Paddle OCR

    """
    try:
        finaltext = ''
        ocr = PaddleOCR(lang='en', use_angle_cls=True)
        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

        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'))