Let us see how to read a PDF that is converting a textual PDF file into audio.
- pyttsx3: It is a Python library for Text to Speech. It has many functions which will help the machine to communicate with us. It will help the machine to speak to us
- PyPDF2: It will help to the text from the PDF. A Pure-Python library built as a PDF toolkit. It is capable of extracting document information, splitting documents page by page, merging documents page by page etc.
Both these modules need to be installed
pip install pyttsx3 pip install PyPDF2
You also need to know about the open() function which will help us to open the PDF in read mode. Knowledge about the OOPS Concept is also recommended.
Here is the link of the PDF which is read in the example: https://drive.google.com/file/d/1zhf7-_v6CVUtgd_XMK562mg6ciewi1QR/view?usp=sharing
- Import the PyPDF2 and pyttx3 modules.
- Open the PDF file.
- Use PdfFileReader() to read the PDF. We just have to give the path of the PDF as the argument.
- Use the getPage() method to select the page to be read.
- Extract the text from the page using extractText().
- Instantiate a pyttx3 object.
- Use the say() and runwait() methods to speak out the text.
Now here the code for it
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.
- Python: Convert Speech to text and text to Speech
- Convert Text and Text File to PDF using Python
- Speech Recognition in Python using Google Speech API
- Send PDF File through Email using pdf-mail module
- Convert Text to Speech in Python using win32com.client
- Python | Speech recognition on large audio files
- Extract text from PDF File using Python
- Convert Text to Speech in Python
- Python | Convert image to text and then to speech
- Python | Text to Speech by using pyttsx3
- Text to speech GUI convertor using Tkinter in Python
- Speech To Text using IBM Watson Studio
- Text-To-Speech changing voice in Python
- Python Text To Speech | pyttsx module
- Modifying PDF file using Python
- Convert PDF to Image using Python
- Access metadata of various audio and video file formats using Python - tinytag library
- Convert Text File to CSV using Python Pandas
- Video to Audio convert using Python
- Python Convert Html to PDF
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.