-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtext_to_audio.py
More file actions
71 lines (55 loc) · 1.99 KB
/
text_to_audio.py
File metadata and controls
71 lines (55 loc) · 1.99 KB
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
64
65
66
67
68
69
70
71
import PyPDF2
from gtts import gTTS
from appJar import gui
from pathlib import Path
def pdf_to_audio(input_file,output_file):
pdfFileObj = open(input_file, "rb")
pdfReader = PyPDF2.PdfFileReader(pdfFileObj)
mytext = ""
for pageNum in range(pdfReader.numPages):
pageObj = pdfReader.getPage(pageNum)
mytext += pageObj.extractText()
pdfFileObj.close()
tts = gTTS(text=mytext, lang='en')
save=str(output_file)+".mp3"
tts.save(save)
if(app.questionBox("File Save", "Output PDF saved.Amar Do you want to quit?")):
app.stop()
def validate_inputs(src_file, dest_dir, out_file):
errors = False
error_msgs = []
if (Path(src_file).suffix.upper() != ".PDF"):
errors = True
error_msgs.append("Amar Please select a PDF input file")
if not(Path(dest_dir)).exists():
errors = True
error_msgs.append("Please Select a valid output directory")
# Check for a file name
if len(out_file) < 1:
errors = True
error_msgs.append("Amar Please enter a file name")
return(errors, error_msgs)
def press(button):
if button=="Process":
src_file = app.getEntry("Input_File")
dest_dir = app.getEntry("Output_Directory")
out_file = app.getEntry("Output_name")
errors, error_msg = validate_inputs(src_file, dest_dir, out_file)
if errors:
app.errorBox("Error", "\n".join(error_msg), parent=None)
else:
pdf_to_audio(src_file,Path(dest_dir,out_file))
else:
app.stop()
app=gui("Gift from Amar PDF to Audio Conversion", useTtk=True)
app.setTtkTheme('alt')
app.setSize(500, 200)
# Add the interactive components
app.addLabel("Ashis Choose Source PDF File to convert to audio")
app.addFileEntry("Input_File")
app.addLabel("Select Output Directory")
app.addDirectoryEntry("Output_Directory")
app.addLabel("Output file name")
app.addEntry("Output_name")
app.addButtons(["Process", "Quit","No","InnerEye"],press)
app.go()