termux / termux-api

Termux add-on app which exposes device functionality as API to command line programs.
https://f-droid.org/en/packages/com.termux.api/
2.3k stars 454 forks source link

termux-tts-speak crashes when multiple instances are executed #87

Open fiiim opened 7 years ago

fiiim commented 7 years ago

I have made a script that reads messages in a groupchat with different voices for different persons using termux, termux-tts-speak, acapela voices, ii, hangups, pickups inotifywait and a bash script of my own.

It works okay, but if two people say something too soon after eachother, then two instances of termux-tts-speak will be executed at the same time and it seems to crash the whole voice synth thing.

Is this a limitation of android? or is there some sort of bug in termux? If it is as i suspect a limitation of android, would it be possible to make termux-tts-speak check if another instance of itself is running before starting and if so it will wait a few seconds and try again until no other instances are running.

Would be great because its annoying when it crashes if the script runs too soon or fast.

Neo-Oli commented 7 years ago

Not sure about the crashing, but there is a better way to use termux-tts-speak. Copied from: https://github.com/termux/termux-api/issues/87

mkfifo ~/.tts
while [ true ]; do cat ~/.tts; done | termux-tts-speak

Then you can use it like this:

echo Today is > ~/.tts
date > ~/.tts

This way, there is only one termux-tts-speak process running at all times. It will also be faster, because it doesn't initialize every time. But you can't have multiple voices with that.

Here's another, similar solution, that would work with multiple voices, but sacrifice the speed of the other solution:

mkfifo ~/queue
while [ true ]; do cat ~/queue; done | sh

Then you can do:

echo "termux-tts-speak 'Hello' -p 0.7"> ~/queue

With this you can make sure the commands don't run at the same time.

fiiim commented 7 years ago

Hi. Ive tried your second solution a few days now and it works sort of. but it has to be launched pretty much before everything else, otherwise none of the scripts using it will work properly and it seems somhow get messy anyway sometimes and launch mulitple tts sessions at the same time.

Its kinda similar to my inotify solution only with inotify i use a file instead of fifo.

I think the best solution is to somehow make a script that checks if a termux-tts-speak is running and if it is, wait until its not and then run.

Gonna try and experiment with this and see if i can figure something out.

Thanks for your suggestions btw :)