TGViewer
Python/ django Python/ django @pythonl · 58.5K subscribers
Post #3819 6.68K
🖥 Python-скрипт для озвучивания PDF

# 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}")


@pythonl
  • 👍 37
  • 🔥 8
  • ❤ 5
  • 😁 1
More from @pythonl
  1. Oct 15, 2026🖥 Datadog научила профилировщик Python понимать asyncio: флеймграфы со «стеками из стеков…
  2. Oct 14, 2026📱 35 млрд параметров на смартфоне с потреблением около 3 ГБ оперативной памяти. OpenBMB п…
  3. Oct 12, 2026⚡️ Overmind - open-source слой для автоматической оптимизации AI-агентов. Вместо ручного т…
  4. Oct 12, 2026🖥 Python-дайджест недели: агенты с онтологией, рантайм-проверка типов и SQLite в проде Со…
  5. Oct 10, 2026🐍 Ротация прокси в Python может обходиться без списка IP и `random.choice()` Если провайд…
  6. Oct 9, 2026Вышел Python 3.15: ленивые импорты, frozendict, UTF-8 по умолчанию и JIT, который наконец…
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 →