Skip to content

Commit 1cb83e9

Browse files
authored
Merge pull request hastagAB#275 from ayeshag7/master
Added a python script to convert pdf files to audiobooks
2 parents eaeab2b + 03ef44b commit 1cb83e9

File tree

4 files changed

+35
-0
lines changed

4 files changed

+35
-0
lines changed

PdfToAudio/README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Pdf to Audiobook Converter
2+
This python script generates audio for given pdf files.
3+
4+
## Dependencies / Requirements
5+
- PyPDF2. Install it by typing this command in your terminal `pip install PyPDF2`
6+
- pyttsx3. Install it by `pip install pyttsx3`

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

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@ So far, the following projects have been integrated to this repo:
197197
|[Pressure_Converter](https://github.com/E-wave112/Awesome-Python-Scripts/tree/master/Pressure_Converter)|[E-Wave](https://github.com/E-wave112)|
198198
| [File Carving](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/File_Carving) | [Yeryeong Kim](https://github.com/icarusicarus/) |
199199
|[Google Meet Joiner](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/google_meet_joiner)|[JohanSanSebastian](https://github.com/JohanSanSebastian)|
200+
|[Pdf to AudioBook Converter](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/PdfToAudio)|[Ayesha Gull](https://github.com/ayeshag7/)|
200201

201202
## How to use :
202203

0 commit comments

Comments
 (0)