Here is my code:
import pyttsx3 as audio_converter
import PyPDF2 # version 1.26.0
import time
import sys
book = open("OOP.pdf", "rb")
pdfreader = PyPDF2.PdfFileReader(book)
pages = pdfreader.numPages # to find out number of pages
print(f'PDF name : "Object Oriented Programing (OOP)\nPage number : {pages}"')
speaker = audio_converter.init() # to init the package of pyttsx3
page = pdfreader.getPage(7) # pdf page number + 1 (index 0)
text = page.extractText()
speaker.say(f"Bismillah, Let's read the pdf {text}")
# pdf audio will start after the following commands
for i in range(5, 0, -1):
sys.stdout.write(str(i)+' ')
sys.stdout.flush()
time.sleep(1)
speaker.runAndWait() # this line will read existing pdf only
This code is made for read my pdf and i'm here to countdown the time underneath the for loop using speaker.say(#) i'm expecting here to speak the countdown time from 10 to 0 and that should be pronounced in speaker. in the very first line after the for loop,
sys.stdout.write(str(i)+' ')
when this line prints the countdown i want to use this comman such
speaker.say(str(i)) #but this is an error code
Please assist me
Updating the response:
Trying to focus in the countdown, you need to call say() and after that runAndWait() to make the library play the sound
After that, you can do the same to read the pdf text