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()
Larz60+ write Jul-26-2021, 10:29 AM:
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Fixed for you this time. Please use bbcode tags on future posts.
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Fixed for you this time. Please use bbcode tags on future posts.