Skip to content
Merged
Show file tree
Hide file tree
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
31 changes: 31 additions & 0 deletions AudioBook/PDF_TO_AUDIO.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import pyttsx3
import PyPDF2
from gtts import gTTS
from tkinter.filedialog import askopenfilename
from tkinter import Tk
Tk().withdraw()
filelocation = askopenfilename() # open the dialog GUI


book = open(filelocation, 'rb')

pdfReader = PyPDF2.PdfFileReader(book)
pages = pdfReader.numPages
print("No. of pages: ", pages)
speaker = pyttsx3.init()
whole_text = ''
choice = input('choice? ')

if choice == '1':

for num in range(0, pages):
page = pdfReader.getPage(num)
text = page.extractText()
whole_text += text
speaker.say(text)
print("Reading: ", text)
speaker.runAndWait()


final_file = gTTS(text=whole_text, lang='en') # store file in variable
final_file.save("Output Audio.mp3") # Saving audio file
9 changes: 9 additions & 0 deletions AudioBook/README.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
PDF TO AUDIO (AUDIOBOOK)

You’ll need to install few libraries.
Pytssx3 (pip install pytts3)
PyPDF2 (pip install PyPDF2)
gtts (pip install gtts)

Run the program and a dialog box will appear. Just select the .pdf file you want to convert to audio. PRESS 1 if you want to hear the converted pdf at that moment (and saved afterwards). Otherwise it will be saved automatically.
The .mp3 file will be saved in the same directory.