Converting Pdf Text in to Audio Files
Converting Pdf Text in to Audio Files:
Libraries:-
- PyPDF, is a library in python that is used to read text from a pdf file.
PyPDF2 · PyPI - Pyttsx3, is a text-to-speech convert library.
pyttsx3 · PyPI
Here we are using PyPDF library to read text from the pdf file and then we are converting the text into speech and save it as an audio file.
Program:
import pyttsx3,PyPDF2
pdfrReader=PyPDF2.PdfFileReader(open('File_1.pdf','rb'))
audio=pyttsx3.init()
for page_num in range(pdfrReader.numPages):
text=pdfrReader.getPage(page_num).extractText()
cleanText=text.strip().replace('\n',' ')
print(cleanText)
audio.say(cleanText)
audio.save_to_file(cleanText,'File_1.mp3')
audio.runAndWait()
audio.stop()
THANKS!!
Comments
Post a Comment