config: fix int32/uint32 config value validity check.
[profile/ivi/speech-recognition.git] / run-speech-daemon.sh
1 #!/bin/bash
2
3 VERBOSITY=${VERBOSITY:--vvv}
4 PLUGINDIR=${PLUGINDIR:-$(pwd)/src/.libs}
5 CONFIGFILE=${CONFIGFILE:-$(pwd)/speech-recognition.conf}
6
7 plugins="simple-disambiguator sphinx-speech simple-voice"
8 clients="search-client mpris2-client bluetooth-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 while [ -n "$1" ]; do
77     case $1 in
78         --valgrind)
79             export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$PUGINDIR"
80             opts="${1#--valgrind}"
81             case $opts in
82                 =*) xeq="valgrind ${opts#=}";;
83                  *) xeq="valgrind --leak-check=full";;
84             esac
85             ;;
86          *)
87             EXTRA_OPTIONS="$EXTRA_OPTIONS $1"
88             ;;
89     esac
90     shift
91 done
92
93 $xeq ./src/srs-daemon -f $VERBOSITY -P $PLUGINDIR -c $CONFIGFILE \
94     $LOAD_OPTIONS $PULSESRC $EXTRA_OPTIONS