Initialize the pyttsx3 library, and use getProperty(‘voice’) to get the current gender of the speaker. # Initialize the speaker speaker = pyttsx3.init() rate = speaker.getProperty('rate') print(rate) tProperty('rate', 125) Voice: Change the rate of speaking using setProperty(‘rate’, x), where x=100 being normal speed (1x). Initialize the pyttsx3 library, and use getProperty(‘rate’) to get the current speaking rate. You can tune the speed and volume of speech, and change the voice-over from male to female and vice-versa, depending on your requirements. for page_num in range(pdfReader.numPages): text = pdfReader.getPage(page_num).extractText() speaker.say(text) nAndWait() speaker.stop() Full Implementation:Ĭhanging Voice, Rate, and Volume of pyttsx3 speaker:
Loop the process for every page in the pdf file and stop the pyttsx3 speaker engine as last. It will read out loud the text from the pdf page. Loop through each page, by reading the text and feeding it to the pyttsx3 speaker engine. import pyttsx3 speaker = pyttsx3.init() 3) Play the Audiobook:Įxtract the text from the pdf file page by page using the PyPDF2 implementation. Text that we are reading from a pdf file using the pypdf2 library is fed as an input to the text-to-speech engine. Python has a library pyttsx3, that is capable to convert text-to-speech offline. import PyPDF2 pdfReader = PyPDF2.PdfFileReader(open('file.pdf', 'rb')) 2) Initialize Speaker:
We are using this library to split the pdf file page by page, read the text on each page, and send the text to the next layer/step. merging multiple pages into a single page.extracting document information, such as title, author, etc.Python has library PyPDF2 which is built as a PDF toolkit. Read the full documentation of the pyttsx3 library here. You can install the libraries from PyPl, pip install PyPDF2 pip install pyttsx3 In this article, we will require two libraries ( pyttsx3, PyPDF2) to develop an audiobook. Python has an ocean of libraries that serve various purposes.
In this article, you will know how to develop a basic audiobook in just 7 lines of python code. You do not need to buy a subscription for an audiobook if you have a pdf format of the book. List of popular audiobooks available are: An audiobook is a recording or voice-over of a book or other work being read out loud.