├── a.png ├── aa.png ├── story.pdf ├── try_2.py ├── README.md ├── try_3.py ├── trysum.py ├── try_1.py └── check.py /a.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akhilesh-k/BookWorm/HEAD/a.png -------------------------------------------------------------------------------- /aa.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akhilesh-k/BookWorm/HEAD/aa.png -------------------------------------------------------------------------------- /story.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akhilesh-k/BookWorm/HEAD/story.pdf -------------------------------------------------------------------------------- /try_2.py: -------------------------------------------------------------------------------- 1 | #Import library essentials 2 | from sumy.parsers.plaintext import PlaintextParser 3 | from sumy.nlp.tokenizers import Tokenizer 4 | from sumy.summarizers.lex_rank import LexRankSummarizer 5 | 6 | file ="b.txt" #name of the plain-text file 7 | parser = PlaintextParser.from_file(file, Tokenizer("english")) 8 | summarizer = LexRankSummarizer() 9 | 10 | summary = summarizer(parser.document, 5) #Summarize the document with 5 sentences 11 | 12 | file = open("Summary.txt","w") 13 | for sentence in summary: 14 | file.write(str(sentence)) 15 | file.close() 16 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## BookWorms 2 | --- 3 | BookWorm is a python tool to convert Ebooks to simple audiobook in mp3 format.
4 | ### About BookWorm
5 |
6 | - Use BookWorm to summarize your pdf
7 | - Shorten your stories to listen on the go. 8 | - Convert your whole Ebook to mp3 output. 9 | - Audio Summary of ebook. 10 | 11 |
12 |
13 | ### Requirements

14 | - PdfMiner `$ sudo pip install pdfminer.six`
15 | - Sumy `$ sudo pip install sumy`
16 | - gTTs `$ sudo pip install gtts` 17 | ### How to Use BookWorm
18 |
19 | run `python3 check.py`
20 | Save .pdf files in same directory and use the GUI.
21 | Feel free to fork and contribute. 22 | -------------------------------------------------------------------------------- /try_3.py: -------------------------------------------------------------------------------- 1 | # Import the required module for text 2 | # to speech conversion 3 | from gtts import gTTS 4 | 5 | # This module is imported so that we can 6 | # play the converted audio 7 | import os 8 | with open("b.txt","r") as file: 9 | # The text that you want to convert to audio 10 | mytext = file.readlines() 11 | 12 | # Language in which you want to convert 13 | language = 'en' 14 | 15 | # Passing the text and language to the engine, 16 | # here we have marked slow=False. Which tells 17 | # the module that the converted audio should 18 | # have a high speed 19 | myobj = gTTS(text=str(mytext), lang=language, slow=False) 20 | 21 | # Saving the converted audio in a mp3 file named 22 | # welcome 23 | myobj.save("Audio_Doc.mp3") 24 | 25 | # Playing the converted file 26 | os.system("mpg321 Audio_Doc.mp3") -------------------------------------------------------------------------------- /trysum.py: -------------------------------------------------------------------------------- 1 | # Import the required module for text 2 | # to speech conversion 3 | from gtts import gTTS 4 | 5 | # This module is imported so that we can 6 | # play the converted audio 7 | import os 8 | with open("Summary.txt","r") as file: 9 | # The text that you want to convert to audio 10 | mytext = file.readlines() 11 | 12 | # Language in which you want to convert 13 | language = 'en' 14 | 15 | # Passing the text and language to the engine, 16 | # here we have marked slow=False. Which tells 17 | # the module that the converted audio should 18 | # have a high speed 19 | myobj = gTTS(text=str(mytext), lang=language, slow=False) 20 | 21 | # Saving the converted audio in a mp3 file named 22 | # welcome 23 | myobj.save("Summary.mp3") 24 | 25 | # Playing the converted file 26 | os.system("mpg321 Summary.mp3") 27 | -------------------------------------------------------------------------------- /try_1.py: -------------------------------------------------------------------------------- 1 | from cStringIO import StringIO 2 | from pdfminer.pdfinterp import PDFResourceManager, PDFPageInterpreter 3 | from pdfminer.converter import TextConverter 4 | from pdfminer.layout import LAParams 5 | from pdfminer.pdfpage import PDFPage 6 | import os 7 | import sys, getopt 8 | 9 | #converts pdf, returns its text content as a string 10 | def convert(fname, pages=None): 11 | if not pages: 12 | pagenums = set() 13 | else: 14 | pagenums = set(pages) 15 | 16 | output = StringIO() 17 | manager = PDFResourceManager() 18 | converter = TextConverter(manager, output, laparams=LAParams()) 19 | interpreter = PDFPageInterpreter(manager, converter) 20 | 21 | infile = file(fname, 'rb') 22 | for page in PDFPage.get_pages(infile, pagenums): 23 | interpreter.process_page(page) 24 | infile.close() 25 | converter.close() 26 | text = output.getvalue() 27 | output.close 28 | return text 29 | #converts all pdfs in directory pdfDir, saves all resulting txt files to txtdir 30 | def convertMultiple(pdfDir, txtDir): 31 | if pdfDir == "": pdfDir = os.getcwd() + "\\" #if no pdfDir passed in 32 | for pdf in os.listdir(pdfDir): #iterate through pdfs in pdf directory 33 | fileExtension = pdf.split(".")[-1] 34 | if fileExtension == "pdf": 35 | pdfFilename = pdfDir + pdf 36 | text = convert(pdfFilename) #get string of text content of pdf 37 | text = text.replace('\n', '').replace('\r', '') 38 | textFilename = txtDir + pdf + ".txt" 39 | textFile = open(textFilename, "w") #make text file 40 | textFile.write(text) #write text to text file 41 | def remove_sc(): 42 | import re 43 | string = open('story.pdf.txt').read() 44 | new_str = re.sub('[^a-zA-Z0-9\n\.]', ' ', string) 45 | open('b.txt', 'w').write(new_str) 46 | pdfDir = "/home/akhilesh-k/Desktop/code/" 47 | txtDir = "/home/akhilesh-k/Desktop/code/" 48 | convertMultiple(pdfDir, txtDir) 49 | remove_sc() 50 | -------------------------------------------------------------------------------- /check.py: -------------------------------------------------------------------------------- 1 | #import the 'tkinter' module 2 | import tkinter 3 | import os 4 | import sys 5 | from time import gmtime, strftime 6 | import subprocess 7 | 8 | def cnv(): 9 | 10 | python3_command = "python try_1.py" # launch your python2 script using bash 11 | 12 | process = subprocess.Popen(python3_command.split(), stdout=subprocess.PIPE) 13 | output, error = process.communicate() 14 | def play(): 15 | os.system("vlc Audio_Doc.mp3") 16 | sys.exit(0) 17 | 18 | def save(): 19 | python3_command = "python try_3.py" # launch your python2 script using bash 20 | 21 | process = subprocess.Popen(python3_command.split(), stdout=subprocess.PIPE) 22 | output, error = process.communicate() 23 | 24 | 25 | #def shwpdf(): 26 | # print("ch4k") 27 | # python3_command = "python try_2.py" # launch your python2 script using bash 28 | # 29 | # process = subprocess.Popen(python3_command.split(), stdout=subprocess.PIPE) 30 | # output, error = process.communicate() 31 | # os.system("gedit Summary.txt") 32 | #def listensum(): 33 | # python3_command = "python trysum.py" # launch your python2 script using bash 34 | # process = subprocess.Popen(python3_command.split(), stdout=subprocess.PIPE) 35 | # output, error = process.communicate() 36 | # os.system("rhythmbox Summary.mp3") 37 | 38 | 39 | def main(): 40 | window = tkinter.Tk() 41 | #set the window background to hex code '#a1dbcd' 42 | window.configure(background="#1b4f72") 43 | window.geometry("720x400") 44 | #set the window title 45 | window.title("Listenify") 46 | #set the window icon 47 | 48 | photo = tkinter.PhotoImage(file="aa.png") 49 | w = tkinter.Label(window, image=photo) 50 | w.pack() 51 | 52 | #create a label for the instructions 53 | a1 = tkinter.Label(window, text="Automated Ebook Reader and Summarizer", fg="#383a39", bg="#fff", font=("Helvetica", 22)) 54 | a1.pack() #and pack it into the window 55 | 56 | 57 | #create the widgets for entering a username 58 | b1 = tkinter.Button(window, text="Convert", fg="#383a39", bg="#fff", command=cnv) 59 | 60 | #and pack them into the window 61 | b1.pack() 62 | #l2=tkinter.Button(window,text="Read Summary!",relief="raised",command=shwpdf) 63 | #l2.pack(side="top") 64 | #create the widgets for entering a username 65 | d1 = tkinter.Button(window, text="Listen Story", fg="#fff", bg="#383a39", command=play) 66 | 67 | #and pack them into to the window 68 | d1.pack() 69 | 70 | 71 | #create a button widget called btn 72 | btn = tkinter.Button(window, text="Save Story", fg="#383a39", bg="#a1dbcd", command=save) 73 | #pack the widget into the window 74 | btn.pack() 75 | #yy=tkinter.Button(window,text="Listen Summary!",relief="raised",command=listensum) 76 | #yy.pack(side="top") 77 | b4 = tkinter.Button(window, text="Quit", fg="#fff", bg="#383a39", command=window.destroy) 78 | #pack the widget into the window 79 | b4.pack() 80 | bottomLabel=tkinter.Label(window, text="Created by ACM Team 4") 81 | #draw the window, and start the 'application' 82 | window.mainloop() 83 | main() 84 | --------------------------------------------------------------------------------