MAKE AN AUDIOBOOK FROM PDF FILE USING PYTHON

    Before getting into this, you need to take a look at how to convert text to speech using python and click here to check out.

Program:

# pip install pyttsx3
import pyttsx3
# pip install PyPDF2
import PyPDF2
# Creating object for pyttsx3
engine = pyttsx3.init()
# To open the PDF file
book = open("PDF file location", "rb")
# create PDF File Reader object
pdfreader = PyPDF2.PdfFileReader(book)
# to get the no. of pages
pages = pdfreader.numPages
print(f"No of Pages: {pages}") # prints no. of pages
# iterating each page and extracting text from the PDF
text = ''
for i in range(0, pages):
# Getting a page one by one
page = pdfreader.getPage(i)
# Extracting text and appending to the text variable
extract_text = page.extractText()
text += extract_text
# Converting & storing text to speech in mp3 file
engine.save_to_file(text, "filename.mp3")
engine.runAndWait()

Comments

Popular posts from this blog

MOTION DETECTION AND TRACKING USING OPENCV AND PYTHON

BASIC HAND TRACKING USING PYTHON

PARANTHESIS CHECKER IMPLEMENTATION USING PYTHON - STACK APPLICATON👩‍💻👨‍💻