Are you bored of reading pdfs, soft copies, books? Then here's a solution, you can convert it into an Audiobook and Listen.
Let's get Started
First, we need to install the necessary libraries. We require two libraries to build Audiobooks using Python.
1. PyPDF2
A Pure-Python library built as a PDF toolkit. It is capable of extracting document information splitting documents page by page merging documents page by page cropping pages merging multiple pages into a single page encrypting and decrypting PDF files and more!
So open your terminal and run the following command.
pip install PyPDF2
2. Pyttsx3
pyttsx3 is a text-to-speech conversion library in Python. Unlike alternative libraries, it works offline and is compatible with both Python 2 and 3.
So open your terminal and run the following command.
pip install pyttsx3
Now here the code for it.
import pyttsx3
import PyPDF2
book_name = open('harrypotter.pdf','rb')
pdf_reader = PyPDF2.PdfFileReader(book_name)
pages = pdf_reader.numPages
play = pyttsx3.init()
print('playing....')
for num in range(0,pages):
page = pdf_reader.getPage(num)
text = page.extractText()
play.say(text)
play.runAndWait()
| |
Comments
Post a Comment