Skip to content

Commit d3b3ea8

Browse files
Merge pull request #7 from saberprashant/prashant
GUI file added plus some changes done in readme file
2 parents 92566ad + 045c353 commit d3b3ea8

File tree

3 files changed

+131
-11
lines changed

3 files changed

+131
-11
lines changed

README.md

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# PDF AUDIO READER
1+
# PDF ORATEUR
22

33
A **simple** and **offline** PDF audio reader using Python.
44

@@ -11,8 +11,9 @@ The task can be simply divided into 2 steps:
1111

1212
2. Convert text to speech. Refer [speak.py](https://github.com/nikhilkumarsingh/PDF_AUDIO_READER/blob/master/speak.py) for a sample.
1313

14-
[pdf_audio_reader.py](https://github.com/nikhilkumarsingh/PDF_AUDIO_READER/blob/master/pdf_audio_reader.py) contains the complete code.
15-
14+
[pdf_audio_reader.py](https://github.com/nikhilkumarsingh/PDF_AUDIO_READER/blob/master/pdf_audio_reader.py) contains the complete code for python script.
15+
[pdf_audio_CLI.py](https://github.com/saberprashant/PDF_AUDIO_READER/blob/prashant/pdf_audio_CLI.py) contains the whole code for the Command Line Interface(CLI) of this project.
16+
[pdf_audio_GUI.py](https://github.com/saberprashant/PDF_AUDIO_READER/blob/prashant/pdf_audio_GUI.py) contains the whole code for the GUI version of this project.
1617

1718
## Dependencies
1819

@@ -30,12 +31,8 @@ The task can be simply divided into 2 steps:
3031

3132

3233
## TODOs
33-
- [ ] Suggest a cool name for this project.
34-
3534
- [ ] Create a Python package for this project.
3635

37-
- [ ] A simple desktop GUI.
38-
3936

4037
## Want to contribute?
4138

pdf_audio_CLI.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ def validate_file(file_name):
1919
validate file name(with .pdf) and path.
2020
'''
2121
if not valid_filetype(file_name):
22-
print(INVALID_FILETYPE_MSG % (file_name))
23-
quit()
22+
print(INVALID_FILETYPE_MSG % (file_name))
23+
quit()
2424
elif not valid_path(file_name):
25-
print(INVALID_PATH_MSG % (file_name))
26-
quit()
25+
print(INVALID_PATH_MSG % (file_name))
26+
quit()
2727
return
2828

2929

pdf_audio_GUI.py

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
#dependencies
2+
# for python 3
3+
from tkinter import *
4+
from tkinter import filedialog
5+
import PyPDF2
6+
import pyttsx3
7+
8+
# for python 2 uncomment the following and comment the above one
9+
# from Tkinter import *
10+
# import tkFileDialog #change tkFileDialog in line 17
11+
# import PyPDF2
12+
# import pyttsx3
13+
14+
15+
def extract_text():
16+
'''To extract text from chosen PDF file'''
17+
file = filedialog.askopenfile(parent=root, mode='rb', title='Choose a PDF file')
18+
if file != None:
19+
pdfReader = PyPDF2.PdfFileReader(file)
20+
global mytext
21+
mytext = ""
22+
for pageNum in range(pdfReader.numPages):
23+
pageObj = pdfReader.getPage(pageNum)
24+
mytext += pageObj.extractText()
25+
file.close()
26+
27+
28+
def stop_speaking():
29+
'''To stop the TTS engine on Stop click button'''
30+
engine.stop()
31+
32+
33+
def speak_text():
34+
'''Function to invoke TTS engine to speak the pdf text'''
35+
global rate
36+
global male
37+
global female
38+
rate = int(rate.get()) #getting value from rate entry widget
39+
engine.setProperty('rate', rate) #setting inputted rate
40+
male = int(male.get())
41+
female = int(female.get())
42+
all_voices = engine.getProperty('voices') #extracting all voices from engine
43+
maleVoice = all_voices[0].id #for male voice
44+
femaleVoice = all_voices[1].id #for female voice
45+
if (male == 0 and female == 0) or (male == 1 and female == 1): #default voice-> male
46+
engine.setProperty('voice', maleVoice)
47+
elif male == 0 and female == 1:
48+
engine.setProperty('voice', femaleVoice)
49+
else:
50+
engine.setProperty('voice', maleVoice)
51+
52+
engine.say(mytext)
53+
engine.runAndWait()
54+
55+
56+
57+
def Application(root):
58+
'''Whole gui app'''
59+
root.geometry('{}x{}'.format(600, 500)) #for fixed size window
60+
root.resizable(width=False, height=False)
61+
root.title("PDF Orateur")
62+
root.configure(background="#e0ffff")
63+
global rate, male, female
64+
65+
frame1 = Frame(root, width=500, height=200, bg="#8a2be2") #frame 1 for project name and desc.
66+
frame2 = Frame(root, width=500, height=450, bg="#e0ffff") #frame 2 for rest part
67+
frame1.pack(side="top", fill="both")
68+
frame2.pack(side="top", fill="y")
69+
70+
#frame 1 widgets
71+
name1 = Label(frame1, text="PDF Orateur", fg="white", bg="#8a2be2", font="Arial 28 bold")
72+
name1.pack()
73+
name2 = Label(frame1, text="A simple PDF Audio Reader for you!", fg="white",
74+
bg="#8a2be2", font="Calibri 15")
75+
name2.pack()
76+
77+
#frame 2 widgets
78+
btn = Button(frame2, text='Select PDF file', command=extract_text, activeforeground="red",
79+
padx="70", pady="10", fg="white", bg="black", font="Arial 12")
80+
btn.grid(row=0, pady=20, columnspan=2)
81+
82+
rate_text = Label(frame2, text="Enter Rate of Speech:", fg="black",bg="#e0ffff",
83+
font="Arial 12")
84+
rate_text.grid(row=1, column=0, pady=15, padx=0, sticky=E)
85+
rate = Entry(frame2, text="200", fg="black",bg="white", font="Arial 12")
86+
rate.grid(row=1, column=1, padx=30, pady=15,sticky=W)
87+
# rate.focus_set()
88+
89+
voice_text = Label(frame2, text="Voice:", fg="black",bg="#e0ffff", font="Arial 12")
90+
voice_text.grid(row=2, column=0, pady=15, padx=0, sticky=E)
91+
male = IntVar() #to store male voice option value
92+
maleOpt = Checkbutton(frame2,text="Male",bg="#e0ffff",
93+
variable=male,
94+
onvalue=1,
95+
offvalue=0)
96+
maleOpt.grid(row=2, column=1, pady=0, padx=30, sticky=W)
97+
female = IntVar() #to store female voice option value
98+
femaleOpt = Checkbutton(frame2,text="Female",bg="#e0ffff",
99+
variable=female,
100+
onvalue=1,
101+
offvalue=0)
102+
femaleOpt.grid(row=3, column=1, pady=0, padx=30, sticky=W)
103+
104+
submitBtn = Button(frame2, text='Play PDF file', command=speak_text, activeforeground="red",
105+
padx="60", pady="10", fg="white", bg="black", font="Arial 12")
106+
submitBtn.grid(row=4,column=0, pady=65)
107+
108+
#stop button
109+
stopBtn = Button(frame2, text='Stop playing', command=stop_speaking,activeforeground="red",
110+
padx="60", pady="10", fg="white", bg="black", font="Arial 12")
111+
stopBtn.grid(row=4, column=1, pady=65)
112+
113+
114+
115+
116+
117+
if __name__ == "__main__":
118+
mytext, rate, male, female = "", 100, 0, 0 #global vars
119+
engine = pyttsx3.init()
120+
root = Tk()
121+
Application(root)
122+
root.mainloop()
123+

0 commit comments

Comments
 (0)