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

interrupt in-progress termux-tts-speak / TextToSpeechAPI #266

Open
monking opened this issue May 13, 2019 · 3 comments
Open

interrupt in-progress termux-tts-speak / TextToSpeechAPI #266

monking opened this issue May 13, 2019 · 3 comments

Comments

@monking
Copy link

monking commented May 13, 2019

Feature description

Describe the feature and why you want it.

I would like to be able to stop text-to-speech playback in progress. Some situations where this is useful: perhaps the playback rate or formatting of the text is not ideal, and I'd like to try again. Or perhaps I've piped more text into the TTS engine than I need, in order to search for some information, and I would stop the playback as soon as that information is found.

Background information

Have you checked if the feature is accessible through the android API?

I think this would do the trick:
https://developer.android.com/reference/android/speech/tts/TextToSpeech.html#stop()

This seems to be a public method, rather than static / singleton method, so it might need the original TextToSpeech instance in order to be called. To keep this instance accessible, perhaps there could be an option on the termux-tts-speak script (e.g. -i for "interactive") which causes the script to not return until the speech is done, allowing an interrupt (control+c) signal from the shell to trigger mTts.stop() in TextToSpeechAPI.java.

[EDIT: I thought that the script termux-tts-speak exited right away (perhaps it used to), but I see now that it does not exit until the utterance is complete. So this enhancement might instead be "handle control+c interrupt"]

I'd be happy to code this up, if someone would like to give advice on the architectural decisions (e.g. would I need to refactor the TextToSpeechAPI::onHandleIntent method into separate methods, to account for its newly varied behavior?). I also see that there is already code which seems to run during the whole "utterance" in ResultReturner.returnData (e.g. mTts.setOnUtteranceProgressListener), so it may be as simple as optionally running the meat of this block synchronously.

Do you know of other open-source apps that has a similar feature as the one you want (Provide links)

I will look later and edit if I find some.

@monking
Copy link
Author

monking commented May 13, 2019

I haven't compiled or tested this, but here's a wild guess at the change:
master...monking:stop-tts

@punchagan
Copy link

This request makes sense and would be nice to have! As a work around, I've setup a shell signal handler that kills the TTS service when my script is interrupted or exits. (Currently called on EXIT, but could be changed to be called only on SIGINT)

@sudomain
Copy link

sudomain commented Mar 14, 2023

@monking did your change get tested? I'm using termux-tts-speak as an output module for speech-dispatcher and the last part I need is to get it to cancel a message via SIGKILL

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants