-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpdf_reader.py
More file actions
31 lines (25 loc) · 923 Bytes
/
pdf_reader.py
File metadata and controls
31 lines (25 loc) · 923 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import pyttsx3
import PyPDF2
import os
def read_my_pdf(file_path):
if not os.path.exists(file_path):
print("❌ File not found! Please check the path.")
return
try:
# Initialize the speaker engine
speaker = pyttsx3.init()
with open(file_path, 'rb') as book:
pdf_reader = PyPDF2.PdfReader(book)
pages = len(pdf_reader.pages)
print(f"📖 Found {pages} pages. Starting to read...")
for num in range(pages):
page = pdf_reader.pages[num]
text = page.extract_text()
print(f"Reading page {num + 1}...")
speaker.say(text)
speaker.runAndWait()
except Exception as e:
print(f"❌ An error occurred: {e}")
# Usage: Put the name of your PDF file here
# Example: read_my_pdf('DS_Notes.pdf')
read_my_pdf('sample.pdf')