TGViewer
پایتون | Data Science | Machine Learning پایتون | Data Science | Machine Learning @python4all_pro · 24.2K subscribers
Post #601 4.66K
Python script for PDF audio

# Importing necessary libraries
import PyPDF2
import pyttsx3

# Prompt user for the PDF file name
pdf_filename = input("Enter the PDF file name (including extension): ").strip()                       

# Open the PDF file
try:
    with open(pdf_filename, 'rb') as pdf_file:

        # Create a PdfFileReader object
        pdf_reader = PyPDF2.PdfReader(pdf_file)

        # Get an engine instance for the speech synthesis
        speak = pyttsx3.init()       

        # Iterate through each page and read the text
        for page_num in range(len(pdf_reader.pages)):
            page = pdf_reader.pages[page_num]
            text = page.extract_text()
            if text:
                speak.say(text)
                speak.runAndWait()      

        # Stop the speech engine
        speak.stop()     
        print("Audiobook creation completed.")

except FileNotFoundError:
    print("The specified file was not found.")

except Exception as e:
    print(f"An error occurred: {e}")


#code

🆔 @Python4all_pro
  • ❤ 3
  • ❤‍🔥 1
  • 👍 1
More from @python4all_pro
  1. Oct 4, 2026‌🔴 خبر فوری — انتخاب رشته هوشمند و رایگان با «مسیر» 🔥 «مسیر» نرم‌افزار هوشمند و کاملاً ر…
  2. Oct 3, 2026🟣کتاب Oxford word skills یک بار جایزه بهترین کتاب آموزش زبان انگلیسی سال را دریافت کرده.…
  3. Oct 2, 2026💥 ۲۰۰ هزار تومان تخفیفِ بیشتر علاوه بر تخفیفِ ۷۵ درصدی موجود در سایت | اشتراک یک ساله فرا…
  4. Sep 29, 2026What better way to understand a powerful tool like Claude Code than to build your own vers…
  5. Sep 28, 2026🧨 ۲۰۰ آموزش جدید دیگر، جایگزین آموزش‌های قبلی شد... 💯 ۴۰۰+۲۰۰ آموزش در فرادرس، هر آموزش…
  6. Sep 28, 202625 GitHub Repositories Every Python Developer Should Know! Want to improve your Python ski…
Threads Profile ViewerView any public Threads profile without an account.Open ThreadLook →Writing with AI? Make it sound human.Metric37 rewrites AI drafts so they read naturally. Free AI detector, 1,500 words free.Try Metric37 →