Skip to content

Update main.py #22

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 25 additions & 3 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,34 @@
import pyttsx3
import PyPDF2
book = open('oop.pdf', 'rb')
import pyttsx3

# taking user input to get the pdf to be read(Make sure the pdf is available on the current directory)
pdf_name = input("Enter the name of the pdf to be listened:")
pdf_name = pdf_name + '.pdf'

book = open(pdf_name, 'rb')
pdfReader = PyPDF2.PdfFileReader(book)
pages = pdfReader.numPages

speaker = pyttsx3.init()
for num in range(7, pages):

# set the voice rate
speaker.setProperty('rate', 150)

# set volume
volume = speaker.getProperty('volume')
speaker.setProperty('volume', 1.0)

# set the voice property voices[0] is male and voices[1] is female
v = input("Voice you need : male or female")
x = v.lower()
dict = {'male': 0, 'female': 1}
voices = speaker.getProperty('voices')
speaker.setProperty('voice', voices[dict[x]].id)

# It skips the first page since numbering starts from 0.
for num in range(1, pages):
page = pdfReader.getPage(num)
text = page.extractText()
speaker.say(text)
speaker.runAndWait()