‹ projects

vmc

a voice model creator for CMU Sphinx
Log | Files | Refs | README | LICENSE

install.sh (5400B)


      1 #!/bin/bash
      2 # 
      3 # USAGE =======================================================================
      4 # 
      5 #       bash install.sh 
      6 #       bash install.sh -inc-deps (just the program files, used in development)
      7 #       bash install.sh -refresh (removes program files & CMU Sphinx)
      8 # 
      9 # NOTES =======================================================================
     10 # 
     11 #       Copies the vmc packages into /opt/vmc, and puts the vmc script into
     12 #       /usr/local/bin.  Once there, vmc can be called (with its requisite 
     13 #       options) from anywhere with just vmc.sh.
     14 #
     15 #       The script will use all the computer's cores to compile packages.
     16 #
     17 #       A number of tools are installed to a user-specified location.  These 
     18 #       include SphinxTrain and PocketSphinx.  This installation folder is 
     19 #       presumed to be a direct subdirectory of the user's home directory. 
     20 #
     21 #       This may not work forever, as the CMU Sphinx packages are downloaded 
     22 #       from github, where they are under active development.
     23 # 
     24 # SET VARIABLES ===============================================================
     25 
     26 option="$1"
     27 
     28 # Absolute path to this script & containing folder.  stackoverflow.com/q/242538
     29 script=$(readlink -f "$0")
     30 scriptpath=$(dirname "$script") 
     31 
     32 # CMU Sphinx install location - my static repo or the official source?
     33 CMUsrc="umhau" # or "cmusphinx"
     34 
     35 install_dir="/home/$USER/CMU_Sphinx"
     36 
     37 # FUNCTIONS ===================================================================
     38 
     39 look_for_and_remove_old_installation() {
     40 
     41     if [ -d /opt/vmc ]; then
     42 
     43         sudo rm -rf /opt/vmc
     44         sudo rm -f /usr/local/bin/vmc
     45         sudo rm -f /usr/local/bin/lmc
     46 
     47     fi
     48 
     49 }
     50 
     51 install_dependencies() {
     52 
     53     local CORES=$(nproc --all 2>&1)
     54 
     55     if [ ! -d $install_dir ]; then mkdir $install_dir; fi
     56 
     57     # let apt auto-detect the installation state of the dependencies
     58     sudo apt-get install git swig perl bison libtool-bin automake autoconf -y
     59     sudo apt-get install python-dev python3 python3-pyaudio -y
     60 
     61     # check for and install sphinxbase
     62     echo -n "Checking for SphinxBase...."
     63     if [ ! -d $install_dir/sphinxbase/ ]; then
     64         echo "installing..."; cd $install_dir
     65         git clone "https://github.com/$CMUsrc/sphinxbase.git"
     66         cd ./sphinxbase
     67         ./autogen.sh --with-sphinxbase-build
     68         ./configure 
     69         make -j $CORES
     70         make -j $CORES check
     71         sudo make -j $CORES install
     72         sudo chown -R $USER: $install_dir # bug: dir had root ownership.
     73     else
     74         echo "SphinxBase already installed."
     75     fi
     76 
     77     # check for and install sphinxtrain
     78     echo -n "Checking for sphinxtrain...."
     79     if [ ! -d $install_dir/sphinxtrain/ ]; then
     80         echo "installing..."; cd $install_dir
     81         git clone "https://github.com/$CMUsrc/sphinxtrain.git"
     82         cd ./sphinxtrain
     83         ./autogen.sh
     84         ./configure
     85         make -j $CORES
     86         sudo make -j $CORES install
     87         sudo chown -R $USER: $install_dir # bug: dir had root ownership.
     88     else
     89         echo "SphinxTrain already installed."
     90     fi
     91 
     92     # check for and install pocketsphinx
     93     echo -n "Checking for pocketsphinx..."
     94     if [ ! -d $install_dir/pocketsphinx/ ]; then
     95         echo "installing..."; cd $install_dir
     96         git clone "https://github.com/$CMUsrc/pocketsphinx.git"
     97         cd ./pocketsphinx
     98         ./autogen.sh
     99         ./configure
    100         make -j $CORES clean all
    101         make -j $CORES check
    102         sudo make -j $CORES install
    103         sudo chown -R $USER: $install_dir # bug: dir had root ownership.
    104     else
    105         echo "PocketSphinx already installed."
    106     fi
    107 
    108 }
    109 
    110 create_vmc_directories() {
    111 
    112     sudo mkdir -p /opt/vmc
    113     sudo mkdir -p /opt/vmc/lib
    114 
    115 
    116 }
    117 
    118 install_program_files() {
    119 
    120     # move library
    121     sudo cp -r $scriptpath/lib/* /opt/vmc/lib/
    122 
    123     sudo tar -xf $scriptpath/lib/cmusphinx-en-us-ptm-5.2.tar.gz -C /opt/vmc/lib/
    124     sudo mv /opt/vmc/lib/cmusphinx-en-us-ptm-5.2 /opt/vmc/lib/en-us
    125 
    126     # move vmc into user's path & set as executable
    127     sudo cp $scriptpath/vmc /usr/local/bin/vmc
    128     sudo chmod +x /usr/local/bin/vmc
    129 
    130     # move lmc into user's path  & set as executable
    131     sudo cp $scriptpath/lmc /usr/local/bin/lmc
    132     sudo chmod +x /usr/local/bin/lmc
    133 
    134 }
    135 
    136 copy_CMU_Sphinx_binaries() {
    137 
    138     sudo cp /usr/local/libexec/sphinxtrain/bw /opt/vmc/lib
    139     sudo cp /usr/local/libexec/sphinxtrain/map_adapt /opt/vmc/lib
    140     sudo cp /usr/local/libexec/sphinxtrain/mk_s2sendump /opt/vmc/lib
    141     sudo cp /usr/local/libexec/sphinxtrain/mllr_solve /opt/vmc/lib
    142 
    143 }
    144 
    145 remove_CMU_Sphinx() {
    146 
    147     # this is all the stuff I'm aware of. CMU Sphinx docs are opaque on this.
    148 
    149     sudo rm -f /usr/local/lib/libpocketsphinx*
    150     sudo rm -f /usr/local/lib/libsphinx*
    151     sudo rm -fr /usr/local/lib/sphinxtrain
    152 
    153     sudo rm -fr /usr/local/libexec/sphinxtrain
    154 
    155     sudo rm -fr $install_dir
    156 
    157 }
    158 
    159 
    160 # MAIN ========================================================================
    161 
    162 main() {
    163 
    164     sudo ls 1>/dev/null; echo "installing voice model creator"
    165 
    166     look_for_and_remove_old_installation
    167 
    168     if [ "$option" == "-inc-deps" ]; then install_dependencies;
    169     elif [ "$option" == "-refresh" ]; then remove_CMU_Sphinx; install_dependencies;
    170     else echo "not installing dependencies"; fi
    171 
    172     create_vmc_directories
    173 
    174     install_program_files
    175 
    176     copy_CMU_Sphinx_binaries
    177 
    178     bash $scriptpath/lib/move_ps_files.sh -out_of_lib
    179 
    180     echo -e "\nVMC installation complete"
    181 
    182 }
    183 
    184 main