Created
May 30, 2020 10:51
-
-
Save jaggzh/734f0d3c2e588e01b6be29565dc3c834 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Simple script to do a command upon voice-recognition of.. a command. | |
# It uses pocketsphinx_continuous (which comes from debian's | |
# pocketsphinx package in my case). | |
# For accuracy, similar phrases should be provided. | |
# The LAST phrase on the commandline will trigger the command | |
# (which is the very last thing on the command line) | |
# Example: | |
# voice-recognize-and-command "Useless phrase one" "Useless two" "Useful phrase one" "echo command to execute" | |
# | |
# This will listen for the three phrases, and when the last one is heard, | |
# it'll run the echo command | |
tmpf="/tmp/voice-$RANDOM" | |
umask 077 | |
if [[ "$#" < 2 ]]; then | |
echo "Usage: me [one or more strings] [cmd for last string]" >&2 | |
echo "Example: me 'more keywords' 'final phrase' 'echo final phrase'" | |
echo "I use more keywords because I think it increases accuracy of the final one" | |
exit | |
elif [[ "$#" == 2 ]]; then | |
phr="$1" | |
cmd="$2" | |
printf "%s " pocketsphinx_continuous -keyphrase "$1" -kws_threshold 1e-30 -inmic yes 2>/dev/null | |
echo | |
else | |
args=("$@") | |
phrases=("${args[@]::${#args[@]}-1}") | |
keyphrase="${args[-2]}" | |
cmd="${args[-1]}" | |
printf "We're going to check for these:\n" | |
printf ' %s\n' "${phrases[@]}" | |
printf "On the last we'll execute a command:\n" | |
printf " Keyphrase: $keyphrase\n"; | |
printf " Command: $cmd\n" | |
printf '%s /1e-30/\n' "${phrases[@]}" > "$tmpf" | |
printf "Temp File: $tmpf\n" | |
printf '\n\n\n' | |
read -p 'Hit enter to start' | |
#pocketsphinx_continuous -kws "$tmpf" -kws_threshold 1e-30 -inmic yes | |
#exit | |
#pocketsphinx_continuous -kws "$tmpf" -kws_threshold 1e-30 -inmic yes 2>/dev/null | while read match; do | |
pocketsphinx_continuous -kws "$tmpf" -kws_threshold 1e-30 -inmic yes | while read match; do | |
echo "Found: $match" | |
if echo "$match" | stdbuf -i0 -o0 grep "^$keyphrase$"; then | |
echo 'FOUND KEYPHRASE!' | |
$cmd3d | |
fi | |
done | |
fi | |
#pocketsphinx_continuous -keyphrase "okay computer" -kws_threshold 1e-30 -inmic yes | less |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment