hear
hear copied to clipboard
Option to stop listening after a while
I wish hear
could stop automatically, instead of staying active. Maybe when there is no more input for 3 seconds, or when reaching a user-defined text length?
In my simple game, the user has to say back the word.
say --voice="Samantha" -- "$word [[slnc 400]]"
response=$(hear --mode)
shopt -s nocasematch
if [[ "${response}" == "${word}" ]]; then
echo ✅ $word
else
echo 🛑 wrong. ➡ $word
echo " - press enter for next word -"; read
fi
However pressing CTRL-C to stop the listening it stops the script instead.
Also for scripting, the ESCAPE-DELETE control characters get into the way. A plain text output when the program is complete would be preffered. The --mode output looks like this
[2K
Good[2K
[2K
Good morning
Workarounds:
- stop after 4 seconds:
response=$(timeout 4 hear --mode)
- clean string:
response=$(echo "$response" | sed 's/.*\[2K//g' | tr -d '\r\n')