Convert PDF into Audio Book in any language using Python
We have to convert the pdf into the audio book
Properties-
We translate the text of pdf in required language
Step 1-
Import library-
from gtts import gTTS
import PyPDF2
from googletrans import Translator
from tkinter.filedialog import *
Step 2-
Read the text of pdf using PyPDF2
Using for loop add all the text in one text file
Step 3-
Translate the text to the given language
Eg.English to French
English to hindi
But for this project we translate into hindi
Step 4-
Using gTTS convert the text into mp3 file
Complete code-
from gtts import gTTS
import PyPDF2
from googletrans import Translator
from tkinter.filedialog import *
book=askopenfilename()
pd=PyPDF2.PdfFileReader(book)
total=''
pages=pd.numPages
for num in range(0,pages):
page=pd.getPage(num)
txt=page.extractText()
total+=txt
trans=Translator()
t=trans.translate(total,dest='hi')
obj=gTTS(text=t.text,,lang='hi')
obj.save("mi.mp3")
Thanks for watching
Please subscribe
For Complete –Project visit
https://cp-algorithms.blogspot.com/2020/09/convert-pdf-into-audio-book-in-any.html
Comments
Post a Comment