-
Notifications
You must be signed in to change notification settings - Fork 0
/
audiobook.py
40 lines (30 loc) · 952 Bytes
/
audiobook.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
#imports
import pyttsx3
import pdfplumber
import PyPDF2
#Name of PDF to be converted
name = "The Rising of the Shield Hero Vol 02"
file = './pdf/{}.pdf'.format(name)
pdfFileObj = open(file, 'rb')
pdfReader = PyPDF2.PdfFileReader(pdfFileObj)
pages = pdfReader.numPages
total = ''
with pdfplumber.open(file) as pdf:
for i in range(0,pages):
page = pdf.pages[i]
text = page.extract_text()
pg = ""
#remove page numbers with page marking
#print("Page | %d" % (pg))
text = text.replace("%s" % (pg),"")
#print(text)
total = total + text
print(total)
speaker = pyttsx3.init()
voices = speaker.getProperty('voices')
speaker.setProperty('voice', voices[1].id)
rate = speaker.getProperty('rate')
speaker.setProperty('rate', rate+85)
speaker.save_to_file(total , './output/{}.mp3').format(name)
#speaker.say(total)
speaker.runAndWait()