Skip to content

Instantly share code, notes, and snippets.

@alonsoir
Created August 26, 2024 17:09
Show Gist options
  • Save alonsoir/e1ddf1766cee4e06a031299342c94fb2 to your computer and use it in GitHub Desktop.
Save alonsoir/e1ddf1766cee4e06a031299342c94fb2 to your computer and use it in GitHub Desktop.
It will use say native osx command to read and make a speach about the content.
import PyPDF2
import subprocess
# Open the PDF file (Enter Path To Your PDF)
file = open('fullnotes_lagrangiano_modelo_estandar.pdf', 'rb')
readpdf = PyPDF2.PdfReader(file)
# Iterate over each page in the PDF
for pagenumber in range(len(readpdf.pages)):
# Extract text from the page
page = readpdf.pages[pagenumber]
text = page.extract_text()
# Use the 'say' command to read the text
subprocess.run(['say', '--progress', '-v', 'Flo', '-r', '140', text])
# Close the PDF file
file.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment