Tuesday 15 September 2020

Convert PDF into Audio Book in any language using python

 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



No comments:

Post a Comment

The Future of Web Development: Why Next.js is Going Viral

  Are you ready to level up your web development game? Look no further than Next.js, the latest sensation in the world of web development th...