mirror of
https://github.com/hastagAB/Awesome-Python-Scripts.git
synced 2025-01-18 07:17:00 +00:00
Merge pull request #275 from ayeshag7/master
Added a python script to convert pdf files to audiobooks
This commit is contained in:
commit
1cb83e90ac
6
PdfToAudio/README.md
Normal file
6
PdfToAudio/README.md
Normal file
|
@ -0,0 +1,6 @@
|
|||
# Pdf to Audiobook Converter
|
||||
This python script generates audio for given pdf files.
|
||||
|
||||
## Dependencies / Requirements
|
||||
- PyPDF2. Install it by typing this command in your terminal `pip install PyPDF2`
|
||||
- pyttsx3. Install it by `pip install pyttsx3`
|
26
PdfToAudio/pdf_to_audiobook.py
Normal file
26
PdfToAudio/pdf_to_audiobook.py
Normal file
|
@ -0,0 +1,26 @@
|
|||
# Importing the required packages.
|
||||
import PyPDF2
|
||||
import pyttsx3
|
||||
|
||||
text = None
|
||||
|
||||
# Reading a PDF file from your computer by specifying the path and setting the read mode to binary.
|
||||
pdf_reader = PyPDF2.PdfFileReader(open(r"D:\MyPdf.pdf", "rb"))
|
||||
|
||||
# Getting the handle to speaker i.e. creating a reference to pyttsx3.Engine instance.
|
||||
speaker = pyttsx3.init()
|
||||
|
||||
# Splitting the PDF file into pages and reading one at a time.
|
||||
for page_number in range(pdf_reader.numPages):
|
||||
text = pdf_reader.getPage(page_number).extractText()
|
||||
# Generating speech.
|
||||
speaker.say(text)
|
||||
speaker.runAndWait()
|
||||
|
||||
# Stopping the speaker after the complete audio has been created.
|
||||
speaker.stop()
|
||||
|
||||
# Saving the audiobook to your computer.
|
||||
engine = pyttsx3.init()
|
||||
engine.save_to_file(text, r"D:\MyAudio.mp3")
|
||||
engine.runAndWait()
|
2
PdfToAudio/requirements.txt.txt
Normal file
2
PdfToAudio/requirements.txt.txt
Normal file
|
@ -0,0 +1,2 @@
|
|||
PyPDF2
|
||||
pyttsx3
|
|
@ -197,6 +197,7 @@ So far, the following projects have been integrated to this repo:
|
|||
|[Pressure_Converter](https://github.com/E-wave112/Awesome-Python-Scripts/tree/master/Pressure_Converter)|[E-Wave](https://github.com/E-wave112)|
|
||||
| [File Carving](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/File_Carving) | [Yeryeong Kim](https://github.com/icarusicarus/) |
|
||||
|[Google Meet Joiner](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/google_meet_joiner)|[JohanSanSebastian](https://github.com/JohanSanSebastian)|
|
||||
|[Pdf to AudioBook Converter](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/PdfToAudio)|[Ayesha Gull](https://github.com/ayeshag7/)|
|
||||
|
||||
## How to use :
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user