-
Notifications
You must be signed in to change notification settings - Fork 28
/
app.py
25 lines (21 loc) · 658 Bytes
/
app.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
from PIL import Image
from gtts import gTTS
from pytesseract import image_to_string
def image_to_sound(path_to_image):
"""
Function for converting an image to sound
"""
try:
loaded_image = Image.open(path_to_image)
decoded_text = image_to_string(loaded_image)
cleaned_text = " ".join(decoded_text.split("\n"))
print(cleaned_text)
sound = gTTS(cleaned_text, lang="en")
sound.save("sound.mp3")
return True
except Exception as bug:
print("The bug thrown while excuting the code\n", bug)
return
if __name__ == "__main__":
image_to_sound("image.jpg")
input()