config: fix int32/uint32 config value validity check.
[profile/ivi/speech-recognition.git] / run-voice-test.sh
1 #!/bin/bash
2
3 VERBOSITY=${VERBOSITY:--vvv}
4 PLUGINDIR=${PLUGINDIR:-$(pwd)/src/.libs}
5 CONFIGFILE=${CONFIGFILE:-$(pwd)/voice-test.conf}
6
7 plugins="simple-disambiguator sphinx-speech festival-loader festival-voice"
8 clients="dbus-client"
9 PULSESRC=""
10
11 select_input_device () {
12     local _pcidev _usbdev _dev _cnt _i _def _choice=""
13
14     _pcidev=`pactl list sources | grep Name: | tr -s '\t' ' ' |
15                 sed 's/^ *Name: //g' | grep -v monitor | grep pci`
16     _usbdev=`pactl list sources | grep Name: | tr -s '\t' ' ' |
17                 sed 's/^ *Name: //g' | grep -v monitor | grep usb`
18
19     _cnt=$((`echo $_pcidev | wc -l` + `echo $_usbdev | wc -l`))
20
21     while [ -z "$_choice" ]; do
22     echo "Please select an available input device:"
23     _i=1
24
25     if [ -n "$_usbdev" ]; then
26         echo "    * USB devices:"
27         for _dev in $_usbdev; do
28             [ "$_i" = "1" ] && _def="(default)" || _def=""
29             echo "        $_i: $_dev $_def"
30             _i=$(($_i + 1))
31         done
32     fi
33
34     if [ -n "$_pcidev" ]; then
35         echo "    * PCI devices:"
36         for _dev in $_pcidev; do
37             [ "$_i" = "1" ] && _def="(default)" || _def=""
38             echo "        $_i: $_dev $_def"
39             _i=$(($_i + 1))
40         done
41     fi
42
43     echo "    * Preconfigured device:"
44     echo "        $_i: from the config file"
45
46     read -p "Please select 1 - $_cnt (default: 1): " _choice
47     [ -z "$_choice" ] && _choice=1
48
49     if [ "$_choice" -lt 1 -o "$_choice" -gt $(($_cnt + 1)) ]; then
50         _choice=""
51     fi
52     done
53
54     if [ "$_choice" = "$(($_cnt + 1))" ]; then
55         _dev=""
56     else
57         [ -n "$_usbdev" ] && _t=" " || _t=""
58         _dev=`echo "$_usbdev${_t}$_pcidev" | tr ' ' '\n' |
59                   head -$_choice | tail -1`
60     fi
61
62     PULSESRC="$_dev"
63 }
64
65 select_input_device
66 if [ -n "$PULSESRC" ]; then
67     PULSESRC="-s sphinx.pulsesrc=$PULSESRC"
68 fi
69
70 LOAD_OPTIONS=""
71 for i in $plugins $clients; do
72     LOAD_OPTIONS="$LOAD_OPTIONS -L $i"
73 done
74
75 EXTRA_OPTIONS=""
76 DEBUG_OPTIONS=""
77 while [ -n "$1" ]; do
78     case $1 in
79         --valgrind)
80             export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$PUGINDIR"
81             opts="${1#--valgrind}"
82             case $opts in
83                 =*) xeq="valgrind ${opts#=}";;
84                  *) xeq="valgrind --leak-check=full";;
85             esac
86             ;;
87         -n|--dry-run)
88             xeq=echo
89             ;;
90         -d|--debug)
91             DEBUG_OPTIONS='-d'
92             ;;
93          *)
94             EXTRA_OPTIONS="$EXTRA_OPTIONS $1"
95             ;;
96     esac
97     shift
98 done
99
100 if [ -z "$DEBUG_OPTIONS" ]; then
101     $xeq ./src/srs-daemon -f $VERBOSITY "$DEBUG_OPTIONS" \
102         -P $PLUGINDIR -c $CONFIGFILE \
103         $LOAD_OPTIONS $PULSESRC $EXTRA_OPTIONS
104 else
105     $xeq ./src/srs-daemon -f $VERBOSITY -d '*' \
106         -P $PLUGINDIR -c $CONFIGFILE \
107         $LOAD_OPTIONS $PULSESRC $EXTRA_OPTIONS
108 fi