diff --git a/PDF_to_audio/pdf_to_audio.py b/PDF_to_audio/pdf_to_audio.py index 6ffec42ea9..f04eb6fdf6 100644 --- a/PDF_to_audio/pdf_to_audio.py +++ b/PDF_to_audio/pdf_to_audio.py @@ -6,6 +6,7 @@ """ import PyPDF2 import pyttsx3 +from gtts import gTTS #pip install gTTS from tkinter import Tk from tkinter.filedialog import askopenfilename @@ -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