Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions PDF_to_audio/pdf_to_audio.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"""
import PyPDF2
import pyttsx3
from gtts import gTTS #pip install gTTS
from tkinter import Tk
from tkinter.filedialog import askopenfilename

Expand All @@ -15,10 +16,14 @@

with open(FILE_PATH, "rb") as f: # open the file in reading (rb) mode and call it f
pdf = PyPDF2.PdfFileReader(f)
txt_file=' ' #str variable
#parse every page
for page in pdf.pages:
text = page.extractText()
txt_file+=text #stores text into txt_file variable and convert it into str form as gtts library only saves text file into mp3
## speaking part ####
engine = pyttsx3.init()
engine.say(text)
engine.runAndWait()
audio_file = gTTS(text = txt_file, lang='en') #stores into variable
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