diff --git a/AudioBook/PDF_TO_AUDIO.py b/AudioBook/PDF_TO_AUDIO.py new file mode 100644 index 000000000..d5a9e1fc8 --- /dev/null +++ b/AudioBook/PDF_TO_AUDIO.py @@ -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 diff --git a/AudioBook/README.txt b/AudioBook/README.txt new file mode 100644 index 000000000..4c9cdfed9 --- /dev/null +++ b/AudioBook/README.txt @@ -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.