Skip to content

Instantly share code, notes, and snippets.

@bug-author
Created September 2, 2023 17:56
Show Gist options
  • Save bug-author/4b42655f29195548310bd0cec9879457 to your computer and use it in GitHub Desktop.
Save bug-author/4b42655f29195548310bd0cec9879457 to your computer and use it in GitHub Desktop.
import pdfplumber
from gtts import gTTS
def pdf_to_text(pdf_path):
pdf_text = ""
with pdfplumber.open(pdf_path) as pdf:
for page in pdf.pages:
pdf_text += page.extract_text()
return pdf_text
if __name__ == "__main__":
pdf_path = "sample.pdf"
extracted_text = pdf_to_text(pdf_path)
if extracted_text:
tts = gTTS(text=extracted_text, lang='en')
tts.save("sample_audiobook.mp3")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment