Skip to main content

Create your own Audiobook using python| Ebook| PDF reader using python| python for beginner

 Hello reader's

In this post you are going to see that "How you can create your own audiobook or Ebook" or simply a pdf reader using python. For doing this you must have basic knowledge of python. 




First of all install python on your laptop or desktop or what ever machine you are using, to download python click here.

If you don't know how to install python then you can checkout my other post's in which i have explained how to install python and any IDE which supports python. After the successful installation of python install a IDE which supports python or you can use Python's IDE too. 

There is also a different IDE's which support's python, like - VS Code, Pycharm are well known for python development. 

After the successful installation of python and it's supportive IDE lets get into the code , now you have to install some modules to run the code, Modules are nothing but some files with the “. py” extension containing Python code that can be imported inside another Python Program. In simple terms, we can consider a module to be the same as a code library or a file that contains a set of functions that you want to include in your application. 

now lets install the modules, Open your command prompt and type "pip install pyttsx3" pyttsx3 is a is a text-to-speech conversion library in Python. Unlike alternative libraries, it works offline, and is compatible with both Python 2 and 3. 



installing pyttsx3 using pip in cmd


As you can see in the above picture, i have already installed that's why it is showing me that requirement already satisfied but in your case it will install. 

After the successful installation of pyttsx3 , you have to install one more module named PyPDF2. To install PyPDF2 type "pip install pypdf2" in command prompt. 



installing Pypdf2 using pip in cmd


After the successful installation of code , let's start with code , Open your favourite IDE and type code .

First import all the two modules which you have installed using pip command. so type "import pyttsx3 import PyPDF2"  this lines going to import import the modules. 
now type , "book = open('Filename.pdf', 'rb')"  This line going to fetch the pdf file which you have stored at some location in storage. 
"pdfReader = PyPDF2.PdfFileReader(book)" This line is going to initialize the PyPDF2 module. 
If you want to know that how many pages are there in that perticular file the type "pages = pdfReader.numPages" This line of code is going to tell you that how many number of pages are there in that pdf file. 
Now you have initialize the speaker to speak up or to read the pdf , for initializing the speaker type "speaker = pyttsx3.init()" . 

"for num in range(1, pages):
    page = pdfReader.getPage(num)"  This two lines of code is going tell you that there are how many number of pages are there in pdf. 

"text = page.extractText()
    speaker.say(text)"
 This two lines of code is going to extract text from pdf, mainly these two lines of code are going to read out the pdf. 

   " speaker.runAndWait()"  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.







Code :- 
import pyttsx3
import PyPDF2
book = open('The Django Book ( PDFDrive ).pdf', 'rb')
pdfReader = PyPDF2.PdfFileReader(book)

pages = pdfReader.numPages
speaker = pyttsx3.init()
for num in range(1, pages):
    page = pdfReader.getPage(num)
    text = page.extractText()
    speaker.say(text)
    speaker.runAndWait()

Comments

Post a Comment

Thank you for sharing this.

You’re helping us become better. Want to stay in the loop? Subscribe to our YouTube channel.

Popular posts from this blog

Android 13 features| Android 13 updates| Material You design| language Customizable| Android themes Privacy and security controls in Android 13| App Hibernation in Android 13| Adaptive Charging in Android 13| Android 13 release date| Android Beta Program| Latest Android version

 Android 13: What's New and Exciting? Android 13, codenamed Tiramisu, is the latest version of Google's mobile operating system that is expected to launch in late 2023. Android 13 promises to bring a host of new features and improvements to enhance the user experience, security, and performance of Android devices. In this blog post, we will take a look at some of the most anticipated features of Android 13 and how they will benefit users and developers alike. One of the biggest changes in Android 13 is the introduction of Material You, a new design language that adapts to the user's preferences, mood, and context. Material You allows users to customize their device's theme, colors, fonts, icons, and shapes according to their personal style and taste. Material You also changes dynamically based on the time of day, the wallpaper, the app, and the device mode. For example, if the user switches to dark mode, the system will automatically adjust the colors and brightness to ...

Define a function that computes the length of a given list or string| Python for beginner

 Python is a popular programming language that is widely used by developers and data scientists. One of the fundamental concepts in Python is functions, which are self-contained blocks of code that perform a specific task. In this blog post, we will discuss how to define a function that computes the length of a given list or string using Python. What is a Function? A function is a block of code that performs a specific task. Functions are self-contained and can be called from anywhere in a program. Functions are an essential part of Python and are used extensively in programming. Defining a Function in Python In Python, functions are defined using the 'def' keyword, followed by the name of the function, and a set of parentheses. The body of the function is indented and contains the code that performs the task. Here is an example of a function that computes the length of a given list: def compute_length(list):     length = 0     for item in list:     ...

Define a procedure histogram() that takes a list of integers and prints a histogram to the screen| Histogram procedure| printing histogram| Python histogram function| Python programming

  How to Visualize Data with Python: Defining a Procedure Histogram() When it comes to analyzing data, visualization is key. Being able to see the patterns and trends in your data can make all the difference in understanding it. Luckily, Python has a built-in function for creating histograms, which is a powerful tool for visualizing data. In this blog post, we'll define a procedure called histogram() that takes a list of integers and prints a histogram to the screen. Before we get into the nitty-gritty of the code, let's briefly discuss what a histogram is and why it's useful. A histogram is a graphical representation of a frequency distribution, which is essentially a way to show how often certain values occur in a dataset. It's a great way to get a quick sense of the shape of your data, including its range, distribution, and outliers. Now, let's dive into the code. Here's how you can define a procedure histogram() in Python: def histogram(int_list):     for i ...