Ask coding questions

← Back to all posts
This code wont run and i dont know why( do i need to call any function and whichone?)
chibuezeonejeme

showing #Process finished with exit code 0

Import necessary libraries:

import pyttsx3
import PyPDF2

Read the file in binary mode:

book = open("xomi.pdf", 'rb')

Create a PdfFileReader object:

pdfReader = PyPDF2.PdfFileReader(book)

To determine total number of pages in the PDF file:

pages = pdfReader.numPages

Initialize the speaker:

Here, init() function is used to get a reference to a pyttsx3.Engine instance

speaker = pyttsx3.init()

To access voice property of the speaker:

voices = speaker.getProperty('voices')

Set the speaker's gender: 0-> Male (default), 1-> Female

speaker.setProperty('voice', voices[1].id)

Iterate through the pages you want to access

For accessing specific pages: Iterate through the corresponding page indices

Note: Index of first page-> 0

Here, entire PDF is accessed:

for num in range(pages):

To save the audio output as a MP3 file, within this project:

Make use of any MP3 player to access this recording whenever required

speaker.save_to_file(text, 'audio.mp3')
speaker.runAndWait()

Voters
chibuezeonejeme
Comments
hotnewtop
QuickV

add the repl to this post and ping me (by doing @QuickV ) And I'll reply.

Coder100

please send the repl.