Skip to content

Commit 9f6e099

Browse files
author
Lenar Gasimov
committed
feat: added complete day 90
A Python script that takes a PDF file and converts it into speech.
1 parent 90da655 commit 9f6e099

File tree

6 files changed

+64
-0
lines changed

6 files changed

+64
-0
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ I'll be using this repo as a way for myself to access them as, if and when I nee
110110
- [Day 87](day87): Portfolio Project - [Web Development]
111111
- [Day 88](day88): Portfolio Project - [Web Development]
112112
- [Day 89](day89): Portfolio Project - [GUI Desktop App]
113+
- [Day 90](day90): Portfolio Project - [HTTP Requests & APIs]
113114

114115
## ✔️ Author
115116

day90/Audio.mp3

562 KB
Binary file not shown.

day90/README.md

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Day 90
2+
3+
A Python script that takes a PDF file and converts it into speech.
4+
5+
## Convert PDF to Audiobook
6+
7+
![pdftoaudio](pdftoaudio.png)
8+
9+
Inspired by this: https://roytuts.com/convert-pdf-file-text-to-audio-speech-using-python-and-google-gtts-api/
10+
11+
## ✔️ Author
12+
13+
<img style="border-radius: 50%;" src="https://github.com/lenargasimov.png" width="100px;" alt=""/>
14+
<br>
15+
16+
<p>
17+
<b>Lenar Gasimov</b><br>Python developer | Python, Django, Flask.</p>
18+
19+
20+
[![Twitter Badge](https://img.shields.io/badge/-@lenargasimov-1ca0f1?style=flat-square&labelColor=1ca0f1&logo=twitter&logoColor=white&link=https://twitter.com/lenargasimov)](https://twitter.com/lenargasimov) [![Linkedin Badge](https://img.shields.io/badge/-lenargasimov-blue?style=flat-square&logo=Linkedin&logoColor=white&link=https://www.linkedin.com/in/lenargasimov/)](https://www.linkedin.com/in/lenargasimov/)
21+
[![Gmail Badge](https://img.shields.io/badge/[email protected]?style=flat-square&logo=Gmail&logoColor=white&link=mailto:[email protected])](mailto:[email protected])
22+
23+
<h4>
24+
25+
🚧 Under construction... 🚧
26+
27+
</h4>

day90/main.py

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#Importing Libraries
2+
#Importing Google Text to Speech library
3+
from gtts import gTTS
4+
5+
#Importing PDF reader PyPDF2
6+
import PyPDF2
7+
8+
#Open file Path
9+
pdf_File = open('simple.pdf', 'rb')
10+
11+
#Create PDF Reader Object
12+
pdf_Reader = PyPDF2.PdfFileReader(pdf_File)
13+
count = pdf_Reader.numPages # counts number of pages in pdf
14+
textList = []
15+
16+
#Extracting text data from each page of the pdf file
17+
for i in range(count):
18+
try:
19+
page = pdf_Reader.getPage(i)
20+
textList.append(page.extractText())
21+
except:
22+
pass
23+
24+
#Converting multiline text to single line text
25+
textString = " ".join(textList)
26+
27+
print(textString)
28+
29+
#Set language to english (en)
30+
language = 'en'
31+
32+
#Call GTTS
33+
myAudio = gTTS(text=textString, lang=language, slow=False)
34+
35+
#Save as mp3 file
36+
myAudio.save("Audio.mp3")

day90/pdftoaudio.png

36.3 KB
Loading

day90/simple.pdf

2.73 KB
Binary file not shown.

0 commit comments

Comments
 (0)