Movatterモバイル変換


[0]ホーム

URL:


Open In App
Next Article:
Speech Recognition in Python using Google Speech API
Next article icon

Let us see how to read a PDF that is converting a textual PDF file into audio.

Packages Used:

Both these modules need to be installed

pip install pyttsx3
pip install PyPDF2

You also need to know about theopen() function which will help us to open the PDF in read mode. Knowledge about the OOPS Concept is also recommended.

Approach:

  • Import the PyPDF2 and pyttx3 modules.
  • Open the PDF file.
  • UsePdfFileReader() to read the PDF. We just have to give the path of the PDF as the argument.
  • Use thegetPage() method to select the page to be read.
  • Extract the text from the page usingextractText().
  • Instantiate a pyttx3 object.
  • Use thesay() andrunwait() methods to speak out the text.

Now here the code for it

Python
# importing the modulesimportPyPDF2importpyttsx3# path of the PDF filepath=open('file.pdf','rb')# creating a PdfFileReader objectpdfReader=PyPDF2.PdfFileReader(path)# the page with which you want to start# this will read the page of 25th page.from_page=pdfReader.getPage(24)# extracting the text from the PDFtext=from_page.extractText()# reading the textspeak=pyttsx3.init()speak.say(text)speak.runAndWait()

Output:


Making Audio Book From Any PDF Using Python
Article Tags :
Practice Tags :

Similar Reads

We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood ourCookie Policy &Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences

[8]ページ先頭

©2009-2025 Movatter.jp