-
-
Save JacerOmri/6003852 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
# | |
# Author: Mike Herwig | |
# Enhanced: Jacer Omri | |
# Description: | |
# Simple voice control demonstration using google's speech-api | |
if [ -z "$1" ] | |
then | |
echo "No language supplied, using en\n" | |
LANG="en" | |
else | |
echo "using $1 as language\n" | |
LANG="$1" | |
fi | |
API="http://www.google.com/speech-api/v1/recognize?lang=$LANG" | |
CMD_LIST_DIRECTORY="list directory" | |
CMD_WHOAMI="who am i" | |
JSON=`arecord -f cd -t wav -d 3 -r 16000 | flac - -f --best --sample-rate 16000 -o out.flac;\ | |
wget -O - -o /dev/null --post-file out.flac --header="Content-Type: audio/x-flac; rate=16000" "$API"` | |
UTTERANCE=`echo $JSON\ | |
|sed -e 's/[{}]/''/g'\ | |
|awk -v k="text" '{n=split($0,a,","); for (i=1; i<=n; i++) print a[i]; exit }'\ | |
|awk -F: 'NR==3 { print $3; exit }'\ | |
|sed -e 's/["]/''/g'` | |
echo "utterance: $UTTERANCE" | |
echo "" | |
if [ `echo "$UTTERANCE" | grep -ic "^$CMD_LIST_DIRECTORY$"` -gt 0 ]; then | |
ls . | |
elif [ `echo "$UTTERANCE" | grep -ic "^$CMD_WHOAMI$"` -gt 0 ]; then | |
whoami | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment