Add welcome and color to script.
This commit is contained in:
		
							parent
							
								
									a90d7ec3ca
								
							
						
					
					
						commit
						f39deaf1df
					
				| 
						 | 
				
			
			@ -9,15 +9,45 @@
 | 
			
		|||
# - https://github.com/ideasman42/nerd-dictation
 | 
			
		||||
 | 
			
		||||
set -e
 | 
			
		||||
# Reset
 | 
			
		||||
Color_Off='\e[0m'       # Text Reset
 | 
			
		||||
# Regular Colors
 | 
			
		||||
Black='\e[0;30m'        # Black
 | 
			
		||||
Red='\e[0;31m'          # Red
 | 
			
		||||
Green='\e[0;32m'        # Green
 | 
			
		||||
Yellow='\e[0;33m'       # Yellow
 | 
			
		||||
Blue='\e[0;34m'         # Blue
 | 
			
		||||
Purple='\e[0;35m'       # Purple
 | 
			
		||||
Cyan='\e[0;36m'         # Cyan
 | 
			
		||||
 | 
			
		||||
printwc() {
 | 
			
		||||
    printf "%b$2%b" "$1" "${Color_Off}"
 | 
			
		||||
}
 | 
			
		||||
print_title() {
 | 
			
		||||
printwc "${Blue}" "\n#--------------------------------------------------"
 | 
			
		||||
printwc "${Blue}" "\n# $1"
 | 
			
		||||
printwc "${Blue}" "\n#--------------------------------------------------\n"
 | 
			
		||||
}
 | 
			
		||||
printf '
 | 
			
		||||
########################################################################
 | 
			
		||||
                    Welcome to Nerd-Dictation Installer
 | 
			
		||||
########################################################################
 | 
			
		||||
# Install nerd-dictation offline speech2text tool script using VOSK backend/model.
 | 
			
		||||
#
 | 
			
		||||
# Follow the installer repo at:
 | 
			
		||||
# - https://forge.switnet.net/Ark74/simple-nerd-dictation-installer
 | 
			
		||||
#
 | 
			
		||||
# Nerd Dictation repo at:
 | 
			
		||||
# - https://github.com/ideasman42/nerd-dictation\n\n'
 | 
			
		||||
 | 
			
		||||
if [ "$(id -u)" = 0 ]; then
 | 
			
		||||
   echo "Please don't use with root privileges, sudo will be used only when necessary!"
 | 
			
		||||
   printwc "${Yellow}" "Please don't use with root privileges, sudo will be used only when necessary!"
 | 
			
		||||
   exit 0
 | 
			
		||||
fi
 | 
			
		||||
if dpkg-architecture -e amd64 ;then
 | 
			
		||||
    echo "Supported architecture."
 | 
			
		||||
    printwc "${Green}" "> amd64: supported architecture."
 | 
			
		||||
else
 | 
			
		||||
    echo "Warning: Only run this script on amd64 arch."
 | 
			
		||||
    printwc "${Red}" "> Warning: Only run this script on amd64 arch."
 | 
			
		||||
    exit
 | 
			
		||||
fi
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -31,7 +61,9 @@ CHINESE_VOSK_MODEL="https://alphacephei.com/vosk/models/vosk-model-small-cn-0.22
 | 
			
		|||
NERD_DIC_GIT_REPO="https://github.com/ideasman42/nerd-dictation.git"
 | 
			
		||||
OPT_VOSK="/opt/vosk-python"
 | 
			
		||||
 | 
			
		||||
# Select language.
 | 
			
		||||
#--------------------------------------------------
 | 
			
		||||
print_title "# Select language."
 | 
			
		||||
#--------------------------------------------------
 | 
			
		||||
printf "\n> Vosk Model Language selection.\n"
 | 
			
		||||
PS3='Select one of the available language models to use on nerd-dictation: '
 | 
			
		||||
options=("English" "Spanish" "French" "German" "Chinese" "Exit")
 | 
			
		||||
| 
						 | 
				
			
			@ -68,15 +100,19 @@ do
 | 
			
		|||
            exit 0
 | 
			
		||||
            break
 | 
			
		||||
            ;;
 | 
			
		||||
        *) echo "Invalid option $REPLY, choose one number of the above.";;
 | 
			
		||||
        *) printwc "${Yellow}" "Invalid option $REPLY, choose one number of the above.";;
 | 
			
		||||
    esac
 | 
			
		||||
done
 | 
			
		||||
VOSK_FOLDER="$(basename $VOSK_MODEL|sed 's|.zip||')"
 | 
			
		||||
 | 
			
		||||
# Install dependencies
 | 
			
		||||
#--------------------------------------------------
 | 
			
		||||
print_title "Install dependencies"
 | 
			
		||||
#--------------------------------------------------
 | 
			
		||||
sudo apt-get install -y git ssh python3-setuptools pulseaudio-utils xdotool
 | 
			
		||||
 | 
			
		||||
# Install vosk python3 module.
 | 
			
		||||
#--------------------------------------------------
 | 
			
		||||
print_title "Install vosk python3 module."
 | 
			
		||||
#--------------------------------------------------
 | 
			
		||||
[ -d "$OPT_VOSK" ] && sudo rm -rf "$OPT_VOSK"
 | 
			
		||||
sudo mkdir "$OPT_VOSK"
 | 
			
		||||
cat << EOF  | sudo tee "$OPT_VOSK"/setup.py
 | 
			
		||||
| 
						 | 
				
			
			@ -94,39 +130,47 @@ sudo python3 "$OPT_VOSK"/setup.py install
 | 
			
		|||
if [ $? = 0 ]; then
 | 
			
		||||
    sudo rm "$OPT_VOSK"/setup.py
 | 
			
		||||
else
 | 
			
		||||
    echo "something went wrong, please check setup.py file"
 | 
			
		||||
    printwc "${Red}" "Something went wrong, please check setup.py file"
 | 
			
		||||
    exit
 | 
			
		||||
fi
 | 
			
		||||
 | 
			
		||||
# Cleaning existing local directories and binary link.
 | 
			
		||||
#--------------------------------------------------
 | 
			
		||||
print_title "Cleaning existing local directories and binary link."
 | 
			
		||||
#--------------------------------------------------
 | 
			
		||||
rm -rf "$HOME"/.local/nerd-dictation
 | 
			
		||||
rm -f  "$HOME"/.local/bin/nerd-dictation
 | 
			
		||||
rm -rf "$HOME"/.config/nerd-dictation
 | 
			
		||||
 | 
			
		||||
# Set repo as local package.
 | 
			
		||||
#--------------------------------------------------
 | 
			
		||||
print_title "Set repo as local package."
 | 
			
		||||
#--------------------------------------------------
 | 
			
		||||
cd "$HOME"/.local
 | 
			
		||||
git clone "$NERD_DIC_GIT_REPO"
 | 
			
		||||
cd nerd-dictation
 | 
			
		||||
 | 
			
		||||
# Setup language model
 | 
			
		||||
#--------------------------------------------------
 | 
			
		||||
print_title "Setup language model"
 | 
			
		||||
#--------------------------------------------------
 | 
			
		||||
wget "$VOSK_MODEL"
 | 
			
		||||
unzip "$(basename $VOSK_MODEL)"
 | 
			
		||||
if [ $? = 0 ]; then
 | 
			
		||||
    rm "$(basename $VOSK_MODEL)"
 | 
			
		||||
else
 | 
			
		||||
    echo "something went wrong, please check $(basename $VOSK_MODEL) file"
 | 
			
		||||
    printwc "${Red}" "Something went wrong, please check $(basename $VOSK_MODEL) file"
 | 
			
		||||
    exit
 | 
			
		||||
fi
 | 
			
		||||
mv "$VOSK_FOLDER" model
 | 
			
		||||
mkdir "$HOME"/.config/nerd-dictation
 | 
			
		||||
mv model "$HOME"/.config/nerd-dictation/
 | 
			
		||||
 | 
			
		||||
# Setup local bin for nerd-dictation
 | 
			
		||||
#--------------------------------------------------
 | 
			
		||||
print_title "Setup local bin for nerd-dictation"
 | 
			
		||||
#--------------------------------------------------
 | 
			
		||||
[ ! -d "$HOME"/.local/bin ] && mkdir "$HOME"/.local/bin
 | 
			
		||||
ln -s "$HOME"/.local/nerd-dictation/nerd-dictation "$HOME"/.local/bin
 | 
			
		||||
 | 
			
		||||
if [ $? = 0 ]; then
 | 
			
		||||
    echo "Completed script!\nPlease exit and login for nerd-dictation to be used on the terminal."
 | 
			
		||||
    printwc "${Green}" "Completed script!\nPlease exit and login for nerd-dictation to be used on the terminal."
 | 
			
		||||
else
 | 
			
		||||
    echo "Something went wrong please check."
 | 
			
		||||
    printwc "${Red}" "Something went wrong please check the previous output."
 | 
			
		||||
fi
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue