Skip to content

Update main.py #26

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
41 changes: 30 additions & 11 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,31 @@
import pyttsx3
import PyPDF2
book = open('oop.pdf', 'rb')
pdfReader = PyPDF2.PdfFileReader(book)
pages = pdfReader.numPages

speaker = pyttsx3.init()
for num in range(7, pages):
page = pdfReader.getPage(num)
text = page.extractText()
speaker.say(text)
speaker.runAndWait()
from tkinter import *
from tkinter import filedialog
import pyttsx3
import time
win = Tk()
win.geometry("1500x1500")
txt1 = IntVar()
text = Text(win, width=80, height=30)
text.pack(pady=20)
try:
def open_pdf():
file = filedialog.askopenfilename(title="Select a PDF", filetype=(("PDF Files", "*.pdf"), ("All Files", "*.*")))
if file:
pdf_file = PyPDF2.PdfFileReader(file)
page = pdf_file.getPage(txt1.get())
content = page.extractText()
txt = pyttsx3.init()
txt.say(content)
txt.runAndWait()
text.insert(1.0, content)
time.sleep(2)
except FloatingPointError:
pass
bt1_open = Button(win, text="Select the file ", command=open_pdf)
lbl = Label(win, text="input the page to speak")
lbl2 = Entry(win, textvariable=txt1)
lbl.pack()
lbl2.pack()
bt1_open.pack()
win.mainloop()