DAY 8 - Image To Text And Image To Audio Using Python Script
DAY 8 - Image To Text And Image To Audio Using Python Script
1. open a python file from desktop and execute it in python IDLE. That's way, next file will be picked from Desktop by default. That's my personal experience.
Please do this step as a prerequisite
2. Install these libraries using below commands.
Open command prompt and move to path "C:\Users\Rakesh.Ranjan\AppData\Local\Programs\Python\Python37-32\Scripts>" and then execute below commands
>>> pip install pytesseract ## will convert the image to text string
>>> pip install googletrans ## google translator library
>>> pip install gTTS ##Text To Audio
3.
# import the following libraries
# will convert the image to text string
import pytesseract
# adds image processing capabilities
from PIL import Image
#translates into the mentioned language
from googletrans import Translator
# Text To Audio
from gtts import gTTS
# opening an image from the source path
img = Image.open('WhySearchOnGoogle.JPG') # file will be picked from Desktop as we have defaulted this by executing the Step 1
# describes image format in the output
print(img)
#download Terreract-OSR from "https://github.com/UB-Mannheim/tesseract/wiki" and install it
# path where the tesseract.exe is installed
pytesseract.pytesseract.tesseract_cmd ='C:/Users/Rakesh.Ranjan/AppData/Local/Tesseract-OCR/tesseract.exe'
# converts the image to result and saves it into result variable
result = pytesseract.image_to_string(img)
# write text in a text file and save it to source path
with open('imagetotextRakesh.txt',mode ='w') as file:
file.write(result)
print(result)
p = Translator()
# translates the text into Hindi language
k = p.translate(result,dest='hindi')
print(k)
#steps to translate text to audio file
mytext = result
language = 'en'
myobj = gTTS(text=mytext, lang=language, slow=False)
myobj.save("ImageToAudioRakesh.mp3")
#RR #Day8 #Python #ImageToText #ImageToAudio #HappyLearning #WeLearnEveryday
1. open a python file from desktop and execute it in python IDLE. That's way, next file will be picked from Desktop by default. That's my personal experience.
Please do this step as a prerequisite
2. Install these libraries using below commands.
>>> pip install pytesseract ## will convert the image to text string
>>> pip install googletrans ## google translator library
>>> pip install gTTS ##Text To Audio
3.
# import the following libraries
# will convert the image to text string
import pytesseract
# adds image processing capabilities
from PIL import Image
#translates into the mentioned language
from googletrans import Translator
# Text To Audio
from gtts import gTTS
# opening an image from the source path
img = Image.open('WhySearchOnGoogle.JPG') # file will be picked from Desktop as we have defaulted this by executing the Step 1
# describes image format in the output
print(img)
#download Terreract-OSR from "https://github.com/UB-Mannheim/tesseract/wiki" and install it
# path where the tesseract.exe is installed
pytesseract.pytesseract.tesseract_cmd ='C:/Users/Rakesh.Ranjan/AppData/Local/Tesseract-OCR/tesseract.exe'
# converts the image to result and saves it into result variable
result = pytesseract.image_to_string(img)
# write text in a text file and save it to source path
with open('imagetotextRakesh.txt',mode ='w') as file:
file.write(result)
print(result)
p = Translator()
# translates the text into Hindi language
k = p.translate(result,dest='hindi')
print(k)
#steps to translate text to audio file
mytext = result
language = 'en'
myobj = gTTS(text=mytext, lang=language, slow=False)
myobj.save("ImageToAudioRakesh.mp3")
#RR #Day8 #Python #ImageToText #ImageToAudio #HappyLearning #WeLearnEveryday
Comments
Post a Comment