Skip to content

Instantly share code, notes, and snippets.

@dhruvilp
Created September 26, 2020 20:15
Show Gist options
  • Select an option

  • Save dhruvilp/3db9a60bc2af97765071a5c6e7c17bc6 to your computer and use it in GitHub Desktop.

Select an option

Save dhruvilp/3db9a60bc2af97765071a5c6e7c17bc6 to your computer and use it in GitHub Desktop.
Text-to-Speech in Python (12 lines of code)
import pyttsx3
import PyPDF2
book = open('oop.pdf', 'rb')
pdfReader = PyPDF2.PdfFileReader(book)
pages = pdfReader.numPages
speaker = pyttsx3.init()
for num in range(7, pages):
page = pdfReader.getPage(num)
text = page.extractText()
speaker.say(text)
speaker.runAndWait()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment