Now we can make audiobook from any PDF using, Python. Just rename the pdf name, and you got an audio book for no cost!
AudioBook using Python!
Two libraries are needed for making our audiobook
1.) pyttsx3 (It is for text to speech conversion)
2.) PyPDF2 (It is for reading the PDF file and splitting the text)
! pip install pyttsx3 ! pip install PyPDF2
STEPS:
1.) Import Libraries
2.) Create a pdf file object
3.) Create a pdf reader object
book=open('J. R. R. Tolkien - The Hobbit-Harper Collins (1991).pdf','rb') pdfReader=PyPDF2.PdfFileReader(book,strict=False)
4.) Converting the text read to speech
5.) Count the number of pages and run the loop to read
Voila! Your audiobook is ready!
NOTE:
There are three famous TTS engines:
1.) sapi5
2.) nsss
3.) espeak
One can mention it in here(not a complusion, since we are using the library),
speaker = pyttsx3.init()
If you get the error in the above and you use, 'dummy' like:
speaker = pyttsx3.init('dummy')
then you will not hear the audio output, as dummy is for testing only
One can change the rate of speech, volume and voice as mentioned in the documentation of pyttsx3
PS: In the packet you will find the pdf of The Hobbit, so enjoy!
Submitted by Aarya Brahmane (aaryab)
Download packets of source code on Coders Packet
Comments