File tree Expand file tree Collapse file tree 2 files changed +28
-0
lines changed
Expand file tree Collapse file tree 2 files changed +28
-0
lines changed Original file line number Diff line number Diff line change 1+ # Importing the required packages.
2+ import PyPDF2
3+ import pyttsx3
4+
5+ text = None
6+
7+ # Reading a PDF file from your computer by specifying the path and setting the read mode to binary.
8+ pdf_reader = PyPDF2 .PdfFileReader (open (r"D:\MyPdf.pdf" , "rb" ))
9+
10+ # Getting the handle to speaker i.e. creating a reference to pyttsx3.Engine instance.
11+ speaker = pyttsx3 .init ()
12+
13+ # Splitting the PDF file into pages and reading one at a time.
14+ for page_number in range (pdf_reader .numPages ):
15+ text = pdf_reader .getPage (page_number ).extractText ()
16+ # Generating speech.
17+ speaker .say (text )
18+ speaker .runAndWait ()
19+
20+ # Stopping the speaker after the complete audio has been created.
21+ speaker .stop ()
22+
23+ # Saving the audiobook to your computer.
24+ engine = pyttsx3 .init ()
25+ engine .save_to_file (text , r"D:\MyAudio.mp3" )
26+ engine .runAndWait ()
Original file line number Diff line number Diff line change 1+ PyPDF2
2+ pyttsx3
You can’t perform that action at this time.
0 commit comments