From 50cf700ac1697edea0b9258e258701c0cb01f4b2 Mon Sep 17 00:00:00 2001 From: Aakash Agarwal <58568036+Aakasha01Agarwal@users.noreply.github.com> Date: Thu, 8 Oct 2020 10:01:23 +0530 Subject: [PATCH 1/2] Added a pdf to audiobook convertor. --- AudioBook/PDF_TO_AUDIO.py | 31 +++++++++++++++++++++++++++++++ AudioBook/README.txt | 9 +++++++++ 2 files changed, 40 insertions(+) create mode 100644 AudioBook/PDF_TO_AUDIO.py create mode 100644 AudioBook/README.txt diff --git a/AudioBook/PDF_TO_AUDIO.py b/AudioBook/PDF_TO_AUDIO.py new file mode 100644 index 000000000..0c389469c --- /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() # we don't want a full GUI, so keep the root window from appearing +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 \ No newline at end of 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. From d0a8cceb62f0eb068f5a5d9e6eeb2e084069c549 Mon Sep 17 00:00:00 2001 From: Aakash Agarwal <58568036+Aakasha01Agarwal@users.noreply.github.com> Date: Thu, 8 Oct 2020 10:27:12 +0530 Subject: [PATCH 2/2] added pdf to audiobook --- AudioBook/PDF_TO_AUDIO.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/AudioBook/PDF_TO_AUDIO.py b/AudioBook/PDF_TO_AUDIO.py index 0c389469c..d5a9e1fc8 100644 --- a/AudioBook/PDF_TO_AUDIO.py +++ b/AudioBook/PDF_TO_AUDIO.py @@ -3,29 +3,29 @@ from gtts import gTTS from tkinter.filedialog import askopenfilename from tkinter import Tk -Tk().withdraw() # we don't want a full GUI, so keep the root window from appearing -filelocation = askopenfilename() # open the dialog GUI +Tk().withdraw() +filelocation = askopenfilename() # open the dialog GUI -book=open(filelocation,'rb') +book = open(filelocation, 'rb') pdfReader = PyPDF2.PdfFileReader(book) pages = pdfReader.numPages print("No. of pages: ", pages) speaker = pyttsx3.init() -whole_text='' -choice=input('choice? ') +whole_text = '' +choice = input('choice? ') -if choice=='1': +if choice == '1': for num in range(0, pages): page = pdfReader.getPage(num) text = page.extractText() - whole_text+=text + 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 \ No newline at end of file +final_file.save("Output Audio.mp3") # Saving audio file