DEV Community

Discussion on: Convert any .pdf file 📚 into an audio 🔈 book with Python

Collapse
 
dennisboscodemello1989 profile image
dennisboscodemello1989

Is there any way to pop up an option for choosing the page from which the reading will start & option for choosing the pdf file is there, I am pasting the code

import pyttsx3 as py
import PyPDF2 as pd

pdfReader = pd.PdfFileReader(open('Excel-eBook.pdf', 'rb'))

from tkinter.filedialog import *

speaker = py.init()

voices = speaker.getProperty('voices')

for voice in voices:
speaker.setProperty('voice', voice.id)

book = askopenfilename()
pdfreader = pd.PdfFileReader(book)
pages = pdfreader.numPages

for num in range(0, pages): # O is the number from where the reading will start
page = pdfreader.getPage(num)
text = page.extractText()
player = py.init()
player.say(text)
player.runAndWait()