Skip to content

Commit 0310f27

Browse files
Merge pull request #117 from Mr-Mishraji/patch-1
Saves file into mp3 format as well( answer to #108 )
2 parents 7a053a6 + f8dc964 commit 0310f27

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

PDF_to_audio/pdf_to_audio.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"""
77
import PyPDF2
88
import pyttsx3
9+
from gtts import gTTS #pip install gTTS
910
from tkinter import Tk
1011
from tkinter.filedialog import askopenfilename
1112

@@ -15,10 +16,14 @@
1516

1617
with open(FILE_PATH, "rb") as f: # open the file in reading (rb) mode and call it f
1718
pdf = PyPDF2.PdfFileReader(f)
19+
txt_file=' ' #str variable
1820
#parse every page
1921
for page in pdf.pages:
2022
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
2124
## speaking part ####
2225
engine = pyttsx3.init()
2326
engine.say(text)
2427
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

0 commit comments

Comments
 (0)