My Brain Cells

Easiest (and best) learning materials for anyone with a curiosity for machine learning and artificial intelligence, Deep learning, Programming, and other fun life hacks.

Convert PDF file to AUDIO using Python


Packages used:

pyttsx3: Python library for text to speech. It will help the machine to speak to us.

pyPDF2: It will help to the text from the PDF

Install both the libraries :

                          >>pip install pyttsx3

                          >>pip install pyPDF2

After installing the above packages let’s import them and get started with the task:


  import pyttsx3
import pyPDF2
file = ‘C:/Users/<user_name>/Desktop/Book.pdf’
#Creating a PDF File Object
pdfFileObj = open(file, ‘rb’)
# creating a pdf reader object
pdfReader = PyPDF2.PdfFileReader(pdfFileObj)
#Get the number of pages
pages = pdfReader.numPages
with as pdf:
#Loop through the number of pages
for i in range(0, pages):
page = pdf.pages[i]
text = page.extract_text()
speaker = pyttsx3.init()


Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top