Skip to content

Commit ec995a1

Browse files
authored
Added Files
1 parent 0879d79 commit ec995a1

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

PdfToAudio/pdf_to_audiobook.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
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()

PdfToAudio/requirements.txt.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
PyPDF2
2+
pyttsx3

0 commit comments

Comments
 (0)