Jul-26-2021, 08:25 AM
Hey Everyone, Can anyone tell me below code is correct or not? I am working on Image to Sound based python project and looking to source code. I have found below code from interviewbit and want to know your expert view, Is it right code or not and also I have checked this same code on github
prep:
prep:
Output:pip install pytesseract
pip install gTTS
pip install pytesseract
pip install gTTS
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 executing the code\n", bug) return if __name__ == "__main__": image_to_sound("image.jpg") input()