View Single Post
Old 03-31-2013, 02:25 PM   #39
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
Okay so I added "proper" test for "READY TO RECEIVE command" initialisation.

And hopefully cleaner coding. More comments etc...

Rerolled the second set of tests back into a case selection where possible.

There should be fewer pops and crackles now as the engine is not shut down unnecessarily so often...

PHP Code:
#!/bin/sh
# MAKE PUTTING THINGS IN THE STATUS BAR SANELY BEARABLE
QUOT='{"titleBar":{"clientParams":{"secondary":"'
SECOND='","useDefaultPrimary":false}}}'"'"

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

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

# NOW SETUP A MACHINE SPECIFIC BIN PATH
SYSTEMBIN="/mnt/us/extensions/system/bin/$ARCH"

# SETUP A QUICK KILL COMMAND
SHUSH="killall -9 pocketsphinx_continuous"

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

# CLEAR DOWN ANY OLD JUNK
killall -9 looper.sh
$SHUSH
echo -"" > /var/tmp/talk
echo -"" >/var/tmp/command
echo -"" >/var/tmp/wordmatch
WORDMATCH
="FALSE"  # CREATE DEFAULT NON-MATCH


# SETUP STARTUP ANNOUNCEMENT  ==========================================================
STARTUPANNOUNCE="This is Vague. The Talking Gooey"
# YOU CAN EDIT THIS TO YOUR DESIRES ====================================================

"$SETPROP-s com.lab126.pillow configureChrome -"$QUOT""$STARTUPANNOUNCE""$SECOND

# FORCE 1st loop
/mnt/us/extensions/flite/flite $STARTUPANNOUNCE ." 
sleep 2


# LETS GET THIS PARTY STARTED
"$SETPROP-s com.lab126.pillow configureChrome -"$QUOT""Initialising.""$SECOND"

# STARTUP OUR FIRST BACKGROUND LISTENER
"$LOOPER&

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

#echo "out is $OUT"

# Work our way back down the list in reverse.
"$SYSTEMBIN"/truncate --"$(tail -n1 $LOGFILE | wc -c)" "$LOGFILE"


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

###################################################################################################
######  YOU PROBABLY WANT TO ADD TO THESE COMMANDS WITH YOUR OWN

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

        
case $TRIMVAR in
            
        
"READY") ( echo -"STARTUP" > /var/tmp/wordmatch ) ;;
        
        
# 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'killall runit.shkillall -9 kterm ) ;;
        
        
# 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...
        
        # EXAMPLE BACKGROUND SHELL TASK
        
"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 SOMETHING ELSE")\
        #        ( "$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

#################################################################################################################
## EVERYTHING BELOW HERE YOU PROBABLY DO NOT NEED TO CHANGE

# NOW WE WILL BREAK OUT OF CASE MATCHING TO DO SECONDARY TASKS...
# YEAH YEAH some of this could be cased. - EDIT: Now it is.

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


        
if [ "$WORDMATCH== "QUIT" ] ; then
        $SHUSH
        
/mnt/us/extensions/flite/flite " Goodbye."
        
# EXIT THE APPLICATION
        
        
"$SETPROP-s com.lab126.pillow configureChrome -"$QUOT""Goodbye""$SECOND
        
exit 
        
fi

        
case $WORDMATCH in
        
        
'KINDLET' ) (  $SHUSH
        
"$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
        
        
# Announce Recognised Words
        
/mnt/us/extensions/flite/flite " Cool has been started."
        
sleep 1
        
        
# RESTART OUR BACKGROUND LISTENER
        
"$LOOPER&        
        
        
        ) ;;
        
        
'TRUE' ) (
        
        
# shut down the listener
        
$SHUSH
        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
        
        
# RESTART OUR BACKGROUND LISTENER
        
"$LOOPER&
        
        ) ;;
        
        
'STARTUP' ) (
            
            echo 
"READY!!"
            
# IS THIS A HIGHER DEVICE?
            
if [ "$ARCH== "armv7l" ] ; then
            
"$SETPROP-s com.lab126.pillow configureChrome -"$QUOT""Now Listening.""$SECOND"
            
fi
        
        
) ;;
        
          * )  (
          
        echo 
"NO MATCH was --(""$TRIMVAR"")--"
        "
$SETPROP-s com.lab126.pillow configureChrome -"$QUOT""Phrase not recognised.""$SECOND"
        
/usr/bin/aplay "$EXTDIR""/usr/on3.wav"  
          
          
)  ;; # no-op ; 
        
esac  
        
# END IF VALID PHRASE test
sleep 2
fi

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


fi
done 


I think this is ready for general release now rather than just via github

Last edited by twobob; 03-31-2013 at 02:28 PM.
twobob is offline   Reply With Quote