function build_tools {

        rm exports.txt # Create a new exports file for this run
        touch exports.txt




	echo "Installing festival speech synthesizer"

	# Check whether speech_tools github directory exists

	if [ ! -d tools/speech_tools ]; then

	    echo "Cloning speech_tools git repository"

	    git clone https://github.com/festvox/speech_tools tools/speech_tools

	fi

	## TODO: Check whether all speech_tool files exist.

	if [ ! -f "tools/speech_tools/bin/align" ]; then

	    echo "Building speech_tools"

	    cd tools/speech_tools; ./configure; make; cd -;

	fi

	# Check whether festival github directory exists

	if [ ! -d tools/festival ]; then

	    echo "2. Cloning festival git repository"

	    git clone https://github.com/festvox/festival tools/festival

      #lexes="festlex_CMU festlex_OALD festlex_POSLEX"
      lexes="festlex_POSLEX"
      for lex in $lexes;
      do
        wget http://festvox.org/packed/festival/2.5/$lex.tar.gz; tar xzvf $lex.tar.gz -C tools/
      done

	fi

	if [ ! -f "tools/festival/bin/festival" ]; then

	    echo "2. Building festival speech synthesizer"

	    cd tools/festival; ./configure; make; cd -;

	fi

	if [ -f "tools/festival/bin/festival" ]; then

	    echo "2. Adding festival to path. "
	    echo ""
	    echo "To permamently add festival to your path, add:"
	    echo ""
	    echo 'export PATH=$(pwd)/tools/festival/bin:$PATH'
	    echo ""
	    echo "to your .bashrc or .bash_profile."

	    export PATH=$(pwd)/tools/festival/bin:$PATH
      echo 'export PATH=$(pwd)/tools/festival/bin:$PATH' >> exports.txt
	fi


	echo "2. Downloading and installing festival voices"

	VOICES="festvox_cmu_indic_ben_rm_cg festvox_cmu_indic_guj_ad_cg festvox_cmu_indic_guj_dp_cg festvox_cmu_indic_guj_kt_cg festvox_cmu_indic_hin_ab_cg festvox_cmu_indic_kan_plv_cg festvox_cmu_indic_mar_aup_cg festvox_cmu_indic_mar_slp_cg festvox_cmu_indic_pan_amp_cg festvox_cmu_indic_tam_sdr_cg festvox_cmu_indic_tel_kpn_cg festvox_cmu_indic_tel_sk_cg festvox_cmu_indic_tel_ss_cg festvox_cmu_us_aew_cg festvox_cmu_us_ahw_cg festvox_cmu_us_aup_cg festvox_cmu_us_awb_cg festvox_cmu_us_axb_cg festvox_cmu_us_bdl_cg festvox_cmu_us_clb_cg festvox_cmu_us_eey_cg festvox_cmu_us_fem_cg festvox_cmu_us_gka_cg festvox_cmu_us_jmk_cg festvox_cmu_us_ksp_cg festvox_cmu_us_ljm_cg festvox_cmu_us_lnh_cg festvox_cmu_us_rms_cg festvox_cmu_us_rxr_cg festvox_cmu_us_slp_cg festvox_cmu_us_slt_cg festvox_kallpc16k festvox_rablpc16k"

	for VOICE in $VOICES; do
	    if [ ! -f "tools/$VOICE.tar.gz" ]; then

	       wget "http://festvox.org/packed/festival/2.5/voices/$VOICE.tar.gz" -O tools/$VOICE.tar.gz

	    fi

	    echo "Uncompressing $VOICE.tar.gz"...
	    cd tools; tar xzf $VOICE.tar.gz; cd -

        done
}

while true; do
    read -p "Do you wish to continue installing festival locally? " yn
    case $yn in
        [Yy]* ) build_tools; break;;
        [Nn]* ) exit;;
        * ) echo "Please answer Yes or No.";;
    esac
done


echo "This installation process produced the following exports.txt:"
cat exports.txt

while true; do
    read -p "Do you want to add these exports to your ~/.bashrc? " yn
    case $yn in
	[Yy]* ) cat exports.txt >> $HOME/.bashrc; echo "Execute: source ~/.bashrc for this session"; break;;
	[Nn]* ) exit;;
	*) echo "Please asnwer Yes or No.";;
    esac
done
