File tree Expand file tree Collapse file tree 1 file changed +5
-0
lines changed Expand file tree Collapse file tree 1 file changed +5
-0
lines changed Original file line number Diff line number Diff line change 6
6
"""
7
7
import PyPDF2
8
8
import pyttsx3
9
+ from gtts import gTTS #pip install gTTS
9
10
from tkinter import Tk
10
11
from tkinter .filedialog import askopenfilename
11
12
15
16
16
17
with open (FILE_PATH , "rb" ) as f : # open the file in reading (rb) mode and call it f
17
18
pdf = PyPDF2 .PdfFileReader (f )
19
+ txt_file = ' ' #str variable
18
20
#parse every page
19
21
for page in pdf .pages :
20
22
text = page .extractText ()
23
+ txt_file += text #stores text into txt_file variable and convert it into str form as gtts library only saves text file into mp3
21
24
## speaking part ####
22
25
engine = pyttsx3 .init ()
23
26
engine .say (text )
24
27
engine .runAndWait ()
28
+ audio_file = gTTS (text = txt_file , lang = 'en' ) #stores into variable
29
+ audio_file .save (FILE_PATH .split ('.' )[0 ]+ ".mp3" ) #saves into mp3 format with the same name of pdf in the same directory where pdf is
You can’t perform that action at this time.
0 commit comments