Last active
January 18, 2022 13:15
-
-
Save JayantGoel001/108de603617aa6b8463de92a708b11bd to your computer and use it in GitHub Desktop.
Creating An Audio Book from a PDF File using pyttsx3 and PyPDF2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pyttsx3 | |
import PyPDF2 | |
book = open('poem.pdf', 'rb') | |
pdf_reader = PyPDF2.PdfFileReader(book) | |
num_pages = pdf_reader.numPages | |
play = pyttsx3.init() | |
print("Play the audio book") | |
for num in range(num_pages): | |
page = pdf_reader.getPage(num) | |
data = page.extractText() | |
play.say(data) | |
play.runAndWait() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
I wandered lonely as a cloud | |
That floats on high o'er vales and hills, | |
When all at once I saw a crowd, | |
A host, of golden daffodils; | |
Beside the lake, beneath the trees, | |
Fluttering and dancing in the breeze. | |
Continuous as the stars that shine | |
And twinkle on the milky way, | |
They stretched in never-ending line | |
Along the margin of a bay: | |
Ten thousand saw I at a glance, | |
Tossing their heads in sprightly dance. | |
The waves beside them danced; | |
but they Out-did the sparkling waves in glee: | |
A poet could not but be gay, | |
In such a jocund company: | |
I gazed—and gazed—but little thought | |
What wealth the show to me had brought: | |
For oft, when on my couch I lie | |
In vacant or in pensive mood, | |
They flash upon that inward eye | |
Which is the bliss of solitude; | |
And then my heart with pleasure fills, | |
And dances with the daffodils. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment