View Single Post
Old 03-29-2013, 08:03 PM   #31
twobob
( ͡° ͜ʖ ͡°){ʇlnɐɟ ƃǝs}Týr
twobob ought to be getting tired of karma fortunes by now.twobob ought to be getting tired of karma fortunes by now.twobob ought to be getting tired of karma fortunes by now.twobob ought to be getting tired of karma fortunes by now.twobob ought to be getting tired of karma fortunes by now.twobob ought to be getting tired of karma fortunes by now.twobob ought to be getting tired of karma fortunes by now.twobob ought to be getting tired of karma fortunes by now.twobob ought to be getting tired of karma fortunes by now.twobob ought to be getting tired of karma fortunes by now.twobob ought to be getting tired of karma fortunes by now.
 
twobob's Avatar
 
Posts: 6,586
Karma: 6299993
Join Date: Jun 2012
Location: uti gratia usura (Yao ying da ying; Mo ying da yieng)
Device: PW-WIFI|K5-3G+WIFI| K4|K3-3G|DXG|K2| Rooted Nook Touch
Updated demo with lots of commented out options for the future.

PHP Code:
#!/bin/sh

QUOT='{"titleBar":{"clientParams":{"secondary":"'
SECOND='","useDefaultPrimary":false}}}'"'"

# SETUP SOME PATHS
LOGFILE="/var/tmp/commands"
SETPROP="/usr/bin/lipc-set-prop"
EXTDIR="/mnt/us/extensions/pocketsphinx"
BINARY=$EXTDIR"/usr/local/bin/pocketsphinx_continuous"
LOOPER=$EXTDIR"/looper.sh"
BB="/mnt/us/extensions/system/bin/busybox"

# SETUP STARTUP ANNOUNCEMENT
STARTUPANNOUNCE="This is Vague. The Talking Gooey"

# DETERMINE MACHINE TYPE 
ARCH="`uname -m`"

# LONGEST SENTENCE (like "I[ ]AM[ ]A[ ]SENTENCE[ ]")
SPACEMAX="8"

# CLEAR DOWN ANY OLD JUNK
echo -"" > /var/tmp/talk
echo -"" >/var/tmp/wordmatch
echo -"" >/var/tmp/command

# FORCE 1st loop
echo "$STARTUPANNOUNCE"$LOGFILE"

# START LOOP
while :; 
do 
usleep 50000
OUT
=$(tail -n1 "$LOGFILE"  tr '\n' ' ' )
SPACECOUNT=$(echo "$OUTgrep -" " wc -l)
#echo -n $OUT

TEST=$( echo "$OUTtr -' 'tr -'.')
#echo "TEST is --(""$TEST"")--"
#echo "COMMAND PARSED WAS --(""$OUT"")--"

# DO WE HAVE A COMMAND (remove whitespace for the test)
if [ -"$TEST]; then

# IS A JUMBLE OF WORDS OR LESS THAN 3 WORDS
if [ ! "$SPACECOUNT-le "$SPACEMAX]; then
echo  "Space count $SPACECOUNT Not Less than Maximum spaces allowed $SPACEMAX"
"
$SETPROP-s com.lab126.pillow configureChrome -"$QUOT""Phrase too long... Take it slow""$SECOND"
OUT=""
/usr/bin/aplay "$EXTDIR""/usr/on1.wav"
fi

echo -$OUT ." > /var/tmp/talk 
echo -"$OUT> /var/tmp/command

VAR=$(cat /var/tmp/talk)
TRIMVAR=$(echo "$OUTsed 's/ *$//g')

# IS IT A VALID NON-SPACE ONLY VARIABLE?
if [ -"$TRIMVAR"  ]; then

# RUN POSSIBLE ACTION MATCHING

echo "Case was --(""$TRIMVAR"")--"
echo -"TRUE" > /var/tmp/wordmatch
case $TRIMVAR in

"$STARTUPANNOUNCE")\
        ( echo 
"RECOGNITION INTIALISED" ) ;;

# BACK TO THE HOME PAGE...
"HOME"|"GO HOME"|"CLOSE"|"CLOSE THAT"|"CLOSE IT"|"KILL IT"|"KILL THAT"|"KILL"|"HOME SCREEN")\
        ( 
"$SETPROP-s com.lab126.appmgrd start 'app://com.lab126.booklet.home'; ) ;;

# NOT IMPLEMENTED YET...
#"NEXT PAGE"|"PAGE FORWARD"|"FORWARD"|"PAGE RIGHT")\
#        (  "$SETPROP" -s com.lab126.appmgrd start 'app://com.lab126.booklet.home' ) ;;

# EXAMPLE NATIVE APPLICATION LAUNCH
"BROWSER"|"WEB BROWSER"|"W_W_W"|"WORLD WIDE WEB"|"WEB")\
        ( 
"$SETPROP-s com.lab126.appmgrd start 'app://com.lab126.browser' ) ;;

# EXAMPLE ALTERNATE NATIVE APPLICATION LAUNCH
"OPEN STORE"|"AMAZON STORE"|"OPEN AMAZON STORE"|"BUY BOOKS"|"OPEN AMAZON BOOK STORE")\
        ( 
"$SETPROP-s com.lab126.appmgrd start 'app://com.lab126.store' ) ;;

# EXAMPLE KINDLET LAUNCH
"RUN COOL"|"OPEN COOL"|"SELECT COOL")\
        (  echo -
"KINDLET" > /var/tmp/wordmatch  ) ;;  # They only have 5 seconds to start up so lets really free up resources

# EXAMPLE BACKGROUNDED GTK APPLICATION
"RUN KAY TERM"|"OPEN KAY TERM"|"KAY TERM")\
        (  /
mnt/us/extensions/kterm/bin/runit.sh sleep 2;   ) ;;  # This might need a moment or two...

# LONG RUNNING LOCKING TASK
#"TIME"|"WHATS THE TIME"|"READ ME THE TIME")\
#        (  /mnt/us/extensions/flite/run_voice.sh ;sleep 1 ) ;;  # This could be a locking task... have to think

# LONG RUNNING LOCKING SHELL TASK
#"VAGUE HELP"|"HELP ME VAUGE"|"READ ME THE VAGUE HELP"|"READ ME THE VAGUE HELP TEXT"|"READ VAGUE HELP"|"READ THE VAGUE HELP TEXT" |"VAGUE HELP ME"|"HELP VAGUE")\
#        (  echo -n "HELPME" > /var/tmp/wordmatch  ) ;;  # This could be a locking task... have to think

# EXAMPLE BACKGROUND SHELL TAKS
"OPEN NETWORKING"|"RUN NETWORKING"|"U_S_B NETWORKING"|"RUN U_S_B NETWORKING"|"NETWORK"|"NETWORKING"|"RUN NETWORK")\
        ( /
mnt/us/usbnet/bin/usbnetwork ) ;;

# EXAMPLE LIPC CALL
"SCREEN SAVER"|"POWER OFF"|"POWER DOWN")\
        ( 
"$SETPROP-i com.lab126.powerd preventScreenSaver 0; /usr/bin/powerd_test -) ;;

# EXAMPLE STATEFUL CONTROL
"KILL SCREEN SAVER")\
        ( 
"$SETPROP-i com.lab126.powerd preventScreenSaver 1;  ) ;;

# EXAMPLE OTHER STATEFUL CONTROL... NOT YET IMPLEMENTED
#"KILL SCREEN SAVER")\
#        ( "$SETPROP" -i com.lab126.powerd preventScreenSaver 1;  ) ;;

# CLOSE THE APPLICATION
"SHUT DOWN")\
        ( echo -
"QUIT" > /var/tmp/wordmatch ) ;;

*) ( echo -
"FALSE" > /var/tmp/wordmatch ; echo "Case was $OUT is not processed" )  ;;
esac

# NOW WE WILL BREAK OUT OF CASE MATCHING TO DO SECONDARY TASKS...
# YEAH YEAH some of this could be cased. MEH.

MATCH=$( cat /var/tmp/wordmatch )
echo 
"Words found as command Match = $MATCH"

if [ "$MATCH== "KINDLET" ] ; then
killall 
-9 pocketsphinx_continuous 
"$SETPROP-s com.lab126.pillow configureChrome -"$QUOT""STARTING KUAL!""$SECOND"
usleep 30000;
"$SETPROPcom.lab126.appmgrd start "app://com.lab126.booklet.kindlet/mnt/us/documents/KindleLauncher-2.0.azw2"
sleep 5
fi

# READ OUT THE HELP
#if [ "$MATCH" == "HELPME" ] ; then
#killall -9 pocketsphinx_continuous 
#"$SETPROP" -s com.lab126.pillow configureChrome -s "$QUOT""HELP INFORMATION""$SECOND" 
#/mnt/us/extensions/flite/flite "$EXTDIR""/usr/vague"
#sleep 8
#fi

# EXIT THE APPLICATION
if [ "$MATCH== "QUIT" ] ; then
killall 
-9 pocketsphinx_continuous 
"$SETPROP-s com.lab126.pillow configureChrome -"$QUOT""Goodbye""$SECOND
exit 
fi

if [ "$MATCH== "TRUE" ] ; then

# shut down the listener
killall -9 pocketsphinx_continuous
usleep 10000

# IS THIS A HIGHER DEVICE?
if [ "$ARCH== "armv7l" ] ; then

lipc
-set-prop com.lab126.pillow configureChrome -"$QUOT""$OUT.""$SECOND"  
fi

#echo "WORDS ARE  `cat /var/tmp/talk`"
# Announce Recognised Words
/mnt/us/extensions/flite/flite -/var/tmp/talk &
sleep 1

# START LISTENER AGAIN
"$LOOPER&
else
# ALERT BAD MATCH
"$SETPROP-s com.lab126.pillow configureChrome -"$QUOT""Phase not recognised.""$SECOND"
/usr/bin/aplay "$EXTDIR""/usr/on3.wav"
# End actions on MATCHED
fi

echo -'' > /var/tmp/commands
sleep 2
fi

# TIDY UP AGAIN ?
echo -"" > /var/tmp/talk
echo -"" > /var/tmp/command
echo -"" "$LOGFILE

# IS THIS A HIGHER DEVICE?
if [ "$ARCH== "armv7l" ] ; then
"$SETPROP-s com.lab126.pillow configureChrome -"$QUOT""Now Listening.""$SECOND"

# CLOSE LOOPS
fi
# INDICATE READINESS... RESET SOUND CARD?
/usr/bin/aplay "$EXTDIR""/usr/on2.wav"
fi
done 


This is pretty solid now and I have demonstrated a fair few techniques here.

I'll look to package this for the touch as-is as an alpha and then back port.

The code is already built to run on the 3's.
twobob is offline   Reply With Quote