File tree 1 file changed +21
-16
lines changed
1 file changed +21
-16
lines changed Original file line number Diff line number Diff line change 1
1
import pyttsx3
2
2
import PyPDF2
3
3
4
- book = open ( "DMS.pdf" , "rb" )
5
- pdfReader = PyPDF2 . PdfReader ( book )
4
+ # Initialize pyttsx3 for text-to-speech. Character name Cara.
5
+ Cara = pyttsx3 . init ( )
6
6
7
- pages = len (pdfReader .pages )
8
- # print(pages)
9
- # Access the 4th page (index 3)
10
- page = pdfReader .pages [3 ]
11
- # Extract text from the page
12
- text = page .extract_text ()
7
+ try :
8
+ book = open ("DMS.pdf" , "rb" )
9
+ pdfReader = PyPDF2 .PdfReader (book )
10
+ pages = len (pdfReader .pages )
11
+ except FileNotFoundError :
12
+ print ("The PDF file was not found." )
13
+ exit ()
13
14
14
- # Check if the page contains any text
15
- if text :
16
- # Initialize pyttsx3 for text-to-speech. Character name Cara.
17
- Cara = pyttsx3 .init ()
18
- Cara .say (text )
19
- Cara .runAndWait ()
20
- else :
21
- print ("No text found on the page." )
15
+ for num in range (3 , pages ):
16
+ # Access the 4th page (index 3)
17
+ page = pdfReader .pages [num ]
18
+ # Extract text from the page
19
+ text = page .extract_text ()
20
+
21
+ # Check if the page contains any text
22
+ if text :
23
+ Cara .say (text )
24
+ Cara .runAndWait ()
25
+ else :
26
+ print (f"No text found on page { num + 1 } ." )
You can’t perform that action at this time.
0 commit comments