-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaudiobook_reader.py
49 lines (35 loc) · 1.18 KB
/
audiobook_reader.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
import pyttsx3 as tts
import slate3k as slate
import os
def listenPdf(book):
book_path = 'Books/'+book
with open(book_path,'rb') as book:
text = slate.PDF(book)
listenMore = "y"
while(listenMore == "y"):
pageToListen = int(input("Which page do you want to listen to? "))
print(text[pageToListen])
speaker = tts.init()
speaker.say(text[pageToListen])
speaker.runAndWait()
listenMore = input("Want to listen more? (y / n) ")
if __name__ == '__main__':
lis = os.listdir('Books')
availableBooks = []
for items in lis:
if items.endswith('.pdf'):
availableBooks.append(items)
print(availableBooks)
response = "y"
while(response == 'y'):
book = input("Which book do you want to listen? ")
book = book.split(" ")
book = '_'.join(book)
book = book + '.pdf'
book = book.lower()
if book in availableBooks:
listenPdf(book)
else:
print("Sorry book is not available\nPlease choose another book")
response = input("Want to listen to more books? (y / n)")
response = response.lower()