i basically want the tts to talk while printing out what it is saying. i'v pretty much copied and pasted the pyttsx3 documentation to do this but it just would not work.
import pyttsx3
def onStart(name):
print ('starting', name)
def onWord(name, location, length):
print ('word', name, location, length)
def onEnd(name, completed):
print ('finishing', name, completed)
engine = pyttsx3.init()
engine.connect('started-utterance', onStart)
engine.connect('started-word', onWord)
engine.connect('finished-utterance', onEnd)
engine.say('The quick brown fox jumped over the lazy dog.')
engine.runAndWait()
and the result is this. the word event only fires after the speaking was complete and none of the words are actually printed.
starting None
word None 1 0
finishing None True
iv been working on this for days, iv tried other libraries like win32com.client.Dispatch('SAPI.Spvoice') and gtts, but none seems to be able to do what I want. Sapi.spvoice seems to have an event which would do what I want it, but I cant seem to get that to work either. though I'm not sure I'm doing it correctly either. https://learn.microsoft.com/en-us/previous-versions/windows/desktop/ms723593(v=vs.85)
from win32com.client import Dispatch
import win32com.client
class ContextEvents():
def onWord():
print("the word event occured")
# Work with Result
s = Dispatch('SAPI.Spvoice')
e = win32com.client.WithEvents(s, ContextEvents)
s.Speak('The quick brown fox jumped over the lazy dog.')
from what I understood, there needs to be a class for the events and the event must in the form of On(event) in that class. or something. i tried installing espeak but that did not work out either. keep in mined I'm kinda of a newb in python so if anyone would be willing to give a thorough explination that would be really great.