AudioBook

mail@pastecode.io avatar
unknown
python
3 years ago
583 B
4
Indexable
Never
import PyPDF2
import pyttsx3
import os
#audiobook 
#code from ig:@python.hub
#just checking and chaging working dir (if necessary)
cwd = os.getcwd()
print("Current working directory: {0}".format(cwd))
os.chdir('C:/Users\hp\Documents\GitHub\Python Codes')
speaker = pyttsx3.init()
leitor = PyPDF2.PdfFileReader(open('teste1.pdf', 'rb'))
for page_num in range(leitor.numPages):
    texto = leitor.getPage(page_num).extractText()
    speaker.say(texto)
    speaker.runAndWait()
speaker.stop()

speaker.save_to_file(texto, 'teste1.mp3')
speaker.runAndWait