Python | Convert image to text and then to speechKKaranGupta5scholar39 published articlesReadDiscussCoursesPracticeImprove Article ImproveSave Article SaveLike Article LikeOur goal is to convert a given text image into a string of text, saving it to a file and to hear what is written in the image through audio.For this, we need to import some LibrariesPytesseract(Python-tesseract) : It is an optical character recognition (OCR) tool for python sponsored by google.pyttsx3 : It is an offline cross-platform Text-to-Speech libraryPython Imaging Library (PIL) : It adds image processing capabilities to your Python interpreterGoogletrans : It is a free python library that implements the Google Translate API.Examples: Input : We Have an image with some text Output: THE TEXT FROM THE IMAGE IS EXTRACTED AND A VOICE WILL SPEAK THE TEXT This is the first line of this text example. This is the second line of the same text. Translated(src=en, dest=de, text=Dies ist die erste Zeile von Dieses Textbeispiel. Dies ist die zweite Zeile desselben Textes., pronunciation=None, extra_data="{'translat..." Code : Python code to convert text to speech# import the following libraries# will convert the image to text stringimport pytesseract # adds image processing capabilitiesfrom PIL import Image # converts the text to speech import pyttsx3 #translates into the mentioned languagefrom googletrans import Translator # opening an image from the source pathimg = Image.open('text1.png') # describes image format in the outputprint(img) # path where the tesseract module is installedpytesseract.pytesseract.tesseract_cmd ='C:/Program Files (x86)/Tesseract-OCR/tesseract.exe' # converts the image to result and saves it into result variableresult = pytesseract.image_to_string(img) # write text in a text file and save it to source path with open('abc.txt',mode ='w') as file: file.write(result) print(result) p = Translator() # translates the text into german languagek = p.translate(result,dest='german') print(k)engine = pyttsx3.init() # an audio will be played which speaks the test if pyttsx3 recognizes itengine.say(k) engine.runAndWait()NOTE : We can convert the text into any desired language. For Example Japanese, Russian, Hindi. But the only condition is that the googletrans should recognize the destination language. Also, pyttsx3 will speak only the languages which are recognized by it.Last Updated : 09 Sep, 2019Like Article Save Article Please Login to comment...Similar ReadsPython: Convert Speech to text and text to SpeechSpeech Recognition in Python using Google Speech APIConvert Text to Speech in PythonConvert Text to Speech in Python using win32com.clientConvert PDF File Text to Audio Speech using PythonConvert Text Image to Hand Written Text Image using PythonText-To-Speech changing voice in PythonPython Text To Speech | pyttsx modulePython | Text to Speech by using pyttsx3Text to speech GUI convertor using Tkinter in PythonRelated TutorialsComputer Vision TutorialPandas AI: The Generative AI Python LibraryOpenAI Python API - Complete GuideTop Computer Vision Projects (2023)Python for Kids - Fun Tutorial to Learn Python Programming LikePreviousPython | Arrange the files in directories according to extensionsNext Python | Percentage increase in the total surface area of the cuboidArticle Contributed By :KKaranGupta5KaranGupta5 FollowVote for difficultyCurrent difficulty : EasyEasy Normal Medium Hard ExpertArticle Tags :Machine LearningPythonPractice Tags :Machine LearningpythonReport Issue