Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix issue "'Started-word' event does not work correctly #78" in sapi5 driver for win. #186

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions pyttsx3/drivers/sapi5.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,10 @@ def say(self, text):
self._proxy.setBusy(True)
self._proxy.notify('started-utterance')
self._speaking = True
self._tts.Speak(fromUtf8(toUtf8(text)))
# call this async otherwise this blocks the callbacks
# see SpeechVoiceSpeakFlags: https://docs.microsoft.com/en-us/previous-versions/windows/desktop/ms720892%28v%3dvs.85%29
# and Speak : https://docs.microsoft.com/en-us/previous-versions/windows/desktop/ms723609(v=vs.85)
self._tts.Speak(fromUtf8(toUtf8(text)), 1) # -> stream_number as described in the remarks of the documentation

def stop(self):
if not self._speaking:
Expand Down Expand Up @@ -148,14 +151,18 @@ def __init__(self):
def setDriver(self, driver):
self._driver = driver

def _ISpeechVoiceEvents_StartStream(self, char, length):
def _ISpeechVoiceEvents_StartStream(self, stream_number, stream_position):
self._driver._proxy.notify(
'started-word', location=char, length=length)
'started-word', location=stream_number, length=stream_position)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should probably be 'started-utterance' not 'started-word'. Location and length no longer make sense for StartStream.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are probably right. It has been a while since I look at the code.


def _ISpeechVoiceEvents_EndStream(self, stream, pos):
def _ISpeechVoiceEvents_EndStream(self, stream_number, stream_position):
d = self._driver
if d._speaking:
d._proxy.notify('finished-utterance', completed=not d._stopping)
d._speaking = False
d._stopping = False
d._proxy.setBusy(False)

def _ISpeechVoiceEvents_Word(self, stream_number, stream_position, char, length):
self._driver._proxy.notify(
'started-word', location=char, length=length)