-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
63 lines (49 loc) · 1.72 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import PyPDF2
import pyttsx3
speaker = pyttsx3.init()
rate = speaker.getProperty('rate')
speaker.setProperty('rate', 125)
voices = speaker.getProperty('voices')
def reader():
print('Enter the pdf name:')
name = input('') + '.pdf'
text = open(name, 'rb')
pdfReader = PyPDF2.PdfFileReader(text)
pages = pdfReader.numPages
i = int(input('Enter the page number from ..to start listening..(enter 0 for first page)\n'))
for num in range(i, pages):
print('To go back to main menu..please wait for end of page')
first = pdfReader.getPage(num)
cont = first.extractText()
speaker.say(cont)
speaker.runAndWait()
a = input('Proceed to next page - y/n \n ')
if a == 'y':
continue
elif a == 'n':
break
speaker.stop()
def changevoice():
x = input('For male voice press m and for female voice press f \n')
if x == 'f':
speaker.setProperty('voice', voices[1].id)
elif x == 'm':
speaker.setProperty('voice', voices[0].id)
def changerate():
a = float(input('Enter the desired rate between (i.e. 0.25,0.5...)'))
speaker.setProperty('rate', a * 100)
v = 0
while v != 4:
v = int(input('''Welcome to Free Audio pdf reader ! Now you can listen to any book of your choice completely free.
Press :- 1)start reading
2)Change the gender of the voice
3)Change the speaking rate
4)exit\n'''))
if v == 1:
reader()
elif v == 2:
changevoice()
elif v == 3:
changerate()
else:
print('Thank you for using audiobook !!')