Convert Image to Sound using python | Simple Program | Beginner Project
Convert Image to Sound using python | Simple Program | Beginner Project
Download - https://github.com/UB-Mannheim/tesseract/wiki
- First Install Pytesseract application from above link
- Install the required modules using PIP
- while mapping the tesseract.exe check your system Program Files Path
- Keep your Image File in same directory
- sample File.txt and sound.mp3 will automatically created in same directory
#import modules
from PIL import Image
from gtts import gTTS
import pytesseract
import os
from new import image_to_sound
pytesseract.pytesseract.tesseract_cmd = r"C:\Program Files\Tesseract-OCR\tesseract.exe"
def convert_to_sound(image):
try:
open_image = Image.open(image)
text = pytesseract.image_to_string(open_image)
text_file = " ".join(text.split("\n"))
print(text_file)
sound = gTTS(text_file, lang="en")
sound.save("sound.mp3")
os.system("sound.mp3")
return True
except Exception as bug:
print("The error while executing the code\n", bug)
return
if __name__ == "__main__":
image_to_sound("imagetext.jpg")
input()
Comments
Post a Comment