Create your own audiobook using python

Updated: Sep 24

In Python, there is a module 'PYTTSX3' that is used to convert your text into a speech. This library also works in offline mode and is comfortable for both versions of Python (Python2 and Python 3).

To implement this library, First of all, you must have to install this library in your python terminal:

>>pip install pyttsx3

After installing the library now it's time to read the data from our file.

To extract the data from PDF we will use a third-party tool called PyPDF2. PyPDF2 is an unadulterated python PDF toolbox beginning from the pyPdf project.

To install PyPDF2, run the following command from the command line:

   >> pip install PyPDF2

Now our necessary libraries are installed now it's time to make our audiobook and the python code will be:

import pyttsx3
import PyPDF2
book=open('SWOC Analysis.pdf','rb')
#replace the file name with your pdf file name
#Here, we create an object of PdfFileReader class of PyPDF2 module and pass the pdf file object & get a pdf reader object.
#numPages property gives the number of pages in the pdf file
p1=input("Enetr your name: ")
name=('hi',p1,'I am your audiobook')
print("Number of pages in this pdf are: ",pages)
#pyttsx3. init() factory function is used to get a reference to a pyttsx3.
p=('total number of pages in this pdf are',pages)
for i in range(pages):
    #Retrieves a page by number from this PDF file
    #extractText() is used to extract text from the pdf page.
    tell=('Page number is',page_no)
    # This function will make the speech audible in the system, if you don't write this command then the speech will not be audible to you

I hope you like this


Amandeep Singh

30 views0 comments

Recent Posts

See All