Jiangshan00001 / pyttsx4

Offline Text To Speech synthesis for python
Mozilla Public License 2.0
43 stars 8 forks source link

Interupting an utterance #14

Open gitagogaming opened 1 year ago

gitagogaming commented 1 year ago

trying to interupt a TTS midway thru its speaking.. I have tried this with pyttsx3 and began looking for an alterantive and came across this library but it appears to still be an issue here as well..

I am using Windows 11 and Python 3.11 below is an example taken from the pyttsx3 documentation.

import pyttsx4
def onWord(name, location, length):
   print ('word', name, location, length)
   if location > 2:
      engine.stop()
engine = pyttsx4.init()
engine.connect('started-word', onWord)
engine.say('The quick brown fox jumped over the lazy dog.')
engine.runAndWait()
RxoMTH commented 1 year ago

I tried implementing the code and it outputted a location value of 1. Not sure if that's the reason why the condition in line 4 was not met.

I also wrote a tkinter TTS app using it and I noticed that the engine.stop() wasn't working either.

I tried implementing this solution from StackOverflow and it worked for me on Windows.

In my case, in the line of drivers/sapi5.py where it is written self._tts.Speak('', 3) I edited it to self._tts.Skip('Sentence', 2147483647).

The number 2147483647 is the int.MaxValue

dhaselhan commented 6 months ago

I've opened a pull request to fix this: https://github.com/Jiangshan00001/pyttsx4/pull/21