Skip to content

Commit 77760db

Browse files
Audio Book Readme
1 parent 7f1a574 commit 77760db

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

Audio Book/README.md

+40
Original file line numberDiff line numberDiff line change
@@ -1 +1,41 @@
1+
# Audio Book Using Python🔥
12

3+
An audiobook is a recording or voiceover of a book or other work read aloud. You can listen to audiobooks on any smartphone, tablet, computer, home speaker system, or in-car entertainment system. So, let's learn how to create an audiobook with Python.
4+
5+
## 📌Let’s Create an Audiobook with Python
6+
- Python has a large collection of libraries due to the very active community which serves various purposes. Here we need to use two libraries **pyttsx3** and **PyPDF2** to create an audiobook with Python.
7+
8+
- Both the above libraries can be easily installed by using the pip command.
9+
10+
pip install PyPDF2
11+
pip install pyttsx3
12+
13+
## 📌Reading the PDF File
14+
PyPDF2 allows manipulation of pdf in memory. This python library is capable of tasks such as:
15+
- extract information about the document, such as title, author, etc.
16+
- document division by page
17+
- merge documents per page
18+
- cropping pages
19+
- merge multiple pages into one page
20+
- encrypt and decrypt PDF files
21+
- and more.
22+
23+
I will use this library to split the pdf file page by page, then read the text on each page, then send the text to the next step in the process to create an audiobook with Python.
24+
25+
import PyPDF2
26+
pdfReader = PyPDF2.PdfFileReader(open('file.pdf', 'rb'))
27+
28+
The pyttsx3 library is capable of converting text to speech offline. The text that we read from a pdf is then fed as an input to the text-to-speech engine:
29+
30+
import pyttsx3
31+
speaker = pyttsx3.init()
32+
33+
Now the next step in the process is to loop the process for each page of the pdf file and stop the pyttsx3 speaker engine last:
34+
35+
for page_num in range(pdfReader.numPages):
36+
text = pdfReader.getPage(page_num).extractText()
37+
speaker.say(text)
38+
speaker.runAndWait()
39+
speaker.stop()
40+
41+
This is how we can build an audiobook with Python in a few lines of code.

0 commit comments

Comments
 (0)