Coders Packet

PDF to Audio converter using Python.

By Shubham Suresh Chavan

This is a simple Python program. Where you can give pdf as input then this program will make that PDF Audioable, using only two packages pyttsx3 and PyPDF2

To write this simple Python program you need to install two Python packages.

1.pyttsx: This Python library is used for text to speech conversion.

2.PyPDF2: This python library is used to extract information from documents.

And then import these packages into the program.

import pyttsx3
import PyPDF2

After importing packages you need to give some PDF input and need to count the number of pages as per the given PDF input. 

file=open('read.pdf','rb')
pdfReader=PyPDF2.PdfFileReader(file)
pages=pdfReader.numPages
print("total number of pages:-  ",pages)

Then initialize the speaker and use the say() function to make pdf audible. You can directly jump on a specific page using the getPage() function.

speaker= pyttsx3.init()
page=pdfReader.getPage(7)
text=page.extractText()
speaker.say(text)
speaker.runAndWait()

 

Download Complete Code

Comments

No comments yet