termux / termux/termux-api

interrupt in-progress termux-tts-speak / TextToSpeechAPI

Open
#266 7 comments 4 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Java
Stars
4.3k
Forks
920
PR merge metrics
No merged PRs in 30d

Description

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.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading app/src/main/java/com/termux/api/TextToSpeechAPI.java, the termux-tts-speak command behavior, and the ResultReturner utterance-progress handling mentioned in the issue. Check the Android TextToSpeech.stop() API first; done means an in-progress utterance can be interrupted with Control-C without breaking normal completion behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
android, java
Domain
cli, mobile
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.