├── README.md ├── app.py ├── gene.mp3 ├── image.jpg ├── image_name.png └── sound.mp3 /README.md: -------------------------------------------------------------------------------- 1 | # image-to-sound-python- 2 | 3 | Intro 4 | -------- 5 | This repo will help you get started on how you can get started with Optical character recognition (*OCR*) and speech synthesis in python by building a simple project that will be converting an image into an audible sounds, combining both **OCR** and **SPeech synthesis** in one application 6 | 7 | 8 | Full article 9 | ------------ 10 | The full article for this source code can be found on [my blog](kalebujordan.com) on an article named [How to convert image to sound in Python ](https://kalebujordan.com/image-to-sound-in-python/). 11 | 12 | 13 | Getting started 14 | ----------------- 15 | In order to use this code, firstly clone the repo using **git** or download the zip file manually 16 | 17 | ```bash 18 | $-> git clone https://github.com/Kalebu/image-to-sound-python- 19 | $->cd image-to-sound-python- 20 | $ image-to-sound-python--> python app.py 21 | ``` 22 | 23 | Dependancies 24 | ------------- 25 | In order to run this code you're supposed to have **pytesseract** and **google text to sound** libary installed 26 | on your machine, you can just use *pip* command to this. 27 | 28 | ```bash 29 | -> pip install pytesseract 30 | -> pip install gTTS 31 | ``` 32 | 33 | **Note**: Installing pytesseeract can be an issue sometimes, so there ways in which you could do this effectively, to see how I recommend you going through the article [How to convert image to sound in Python ](https://kalebujordan.com/image-to-sound-in-python/) 34 | . 35 | 36 | 37 | How to run 38 | ------------ 39 | By default the script will load an image with name **image.jpg** from its current directory 40 | to change it adjust the it to be the your new image name. 41 | 42 | drawing 43 | 44 | Explore it 45 | ----------- 46 | Now keep explore it by testing it with various input picture to see what kinda of sound it produces 47 | 48 | Give it a star 49 | -------------- 50 | Did you find this information useful, then give it a star 51 | 52 | 53 | Credits 54 | ----------- 55 | All the credits to [kalebu](github.com/kalebu) 56 | -------------------------------------------------------------------------------- /app.py: -------------------------------------------------------------------------------- 1 | from PIL import Image 2 | from gtts import gTTS 3 | from pytesseract import image_to_string 4 | 5 | 6 | def image_to_sound(path_to_image): 7 | """ 8 | Function for converting an image to sound 9 | """ 10 | try: 11 | loaded_image = Image.open(path_to_image) 12 | decoded_text = image_to_string(loaded_image) 13 | cleaned_text = " ".join(decoded_text.split("\n")) 14 | print(cleaned_text) 15 | sound = gTTS(cleaned_text, lang="en") 16 | sound.save("sound.mp3") 17 | return True 18 | except Exception as bug: 19 | print("The bug thrown while excuting the code\n", bug) 20 | return 21 | 22 | 23 | if __name__ == "__main__": 24 | image_to_sound("image.jpg") 25 | input() -------------------------------------------------------------------------------- /gene.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/karthick-0510/Image_To_Sound_Python/b1071ba22772221e1cff4f0f20208533a502a325/gene.mp3 -------------------------------------------------------------------------------- /image.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/karthick-0510/Image_To_Sound_Python/b1071ba22772221e1cff4f0f20208533a502a325/image.jpg -------------------------------------------------------------------------------- /image_name.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/karthick-0510/Image_To_Sound_Python/b1071ba22772221e1cff4f0f20208533a502a325/image_name.png -------------------------------------------------------------------------------- /sound.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/karthick-0510/Image_To_Sound_Python/b1071ba22772221e1cff4f0f20208533a502a325/sound.mp3 --------------------------------------------------------------------------------