cmulay / PDFtoAudio

Handy Python Automation Script for PDF's to read out loud like audio books.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Python-Automation-Script

This Python Automation Script will read PDF's out loud.

Installation

Check whether you are running latest package manager pip

pip install --upgrade pip

Use the package manager to install pyttsx3.

pip install pyttsx3

Similarly install PyPDF2.

pip install PyPDF2

Usage

Import installed libraries

import pyttsx3 # Python Text to Speech Version 3
import PyPDF2 # Python PDF Reader/Writer 2

Copy & Paste your desired PDF in project folder.

Open the book you want to listen

book = open('pdf_name.pdf', 'rb') # Opens pdf in book (replace pdf_name.pdf with you pdf name)

Pre-work such as reading total number of pages from the book

pdfReader = PyPDF2.PdfFileReader(book) # Reads book
pages = pdfReader.numPages # Calculates total number of pages from book
print(pages) # prints total number of pages  

Initialize Python Text to Speech

bot = pyttsx3.init()
for num in range(0, pages): # from first page (0) to calculated last page
    page = pdfReader.getPage(0)
    # to skip index and pdf clutter replace 0 with your desired page number - 1
    text = page.extractText()
    bot.say(text)
    bot.runAndWait()

License

GNU GENERAL PUBLIC LICENSE

About

Handy Python Automation Script for PDF's to read out loud like audio books.

License:GNU General Public License v3.0


Languages

Language:Python 100.0%