-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathPDF__TO__MP3.py
47 lines (35 loc) · 1.18 KB
/
PDF__TO__MP3.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
import pyttsx3
import PyPDF2
from tkinter import filedialog
location = filedialog.askopenfilename()
full_text =""
with open(location, 'rb') as book:
try:
reader = PyPDF2.PdfFileReader(book)
audio = pyttsx3.init()
print('\n')
print('Recommended Speed ------> 115')
set_speed = input('Please Enter Your Prefered Reading Speed --------> ')
audio.setProperty('rate',int(set_speed))
total_pages = reader.numPages
print('\n')
print('Location of File -------> ' + location)
print('\n')
print('Total Number of Pages -------> ' + str(total_pages))
try:
for page in range(total_pages):
next_page = reader.getPage(page)
content = next_page.extractText()
full_text += content
audio.save_to_file(full_text, 'output.mp3')
print("Converting... \n Please Wait....")
audio.runAndWait()
except:
print('Task Failed Successfully! ')
except:
print('\n')
print('---------> Cannot Read PDF <---------')
print('\n')
print('--------->Invalid PDF format <--------')
print('\n')
print('OR maybe there is something wrong with your brain that you are trying \n to convert a file that is not in .pdf format')