Add welcome and color to script.

This commit is contained in:
Luis Guzmán 2023-10-24 20:55:02 -06:00
parent a90d7ec3ca
commit f39deaf1df
1 changed files with 59 additions and 15 deletions

View File

@ -9,15 +9,45 @@
# - https://github.com/ideasman42/nerd-dictation # - https://github.com/ideasman42/nerd-dictation
set -e 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 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 exit 0
fi fi
if dpkg-architecture -e amd64 ;then if dpkg-architecture -e amd64 ;then
echo "Supported architecture." printwc "${Green}" "> amd64: supported architecture."
else else
echo "Warning: Only run this script on amd64 arch." printwc "${Red}" "> Warning: Only run this script on amd64 arch."
exit exit
fi 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" NERD_DIC_GIT_REPO="https://github.com/ideasman42/nerd-dictation.git"
OPT_VOSK="/opt/vosk-python" OPT_VOSK="/opt/vosk-python"
# Select language. #--------------------------------------------------
print_title "# Select language."
#--------------------------------------------------
printf "\n> Vosk Model Language selection.\n" printf "\n> Vosk Model Language selection.\n"
PS3='Select one of the available language models to use on nerd-dictation: ' PS3='Select one of the available language models to use on nerd-dictation: '
options=("English" "Spanish" "French" "German" "Chinese" "Exit") options=("English" "Spanish" "French" "German" "Chinese" "Exit")
@ -68,15 +100,19 @@ do
exit 0 exit 0
break break
;; ;;
*) echo "Invalid option $REPLY, choose one number of the above.";; *) printwc "${Yellow}" "Invalid option $REPLY, choose one number of the above.";;
esac esac
done done
VOSK_FOLDER="$(basename $VOSK_MODEL|sed 's|.zip||')" 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 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" [ -d "$OPT_VOSK" ] && sudo rm -rf "$OPT_VOSK"
sudo mkdir "$OPT_VOSK" sudo mkdir "$OPT_VOSK"
cat << EOF | sudo tee "$OPT_VOSK"/setup.py cat << EOF | sudo tee "$OPT_VOSK"/setup.py
@ -94,39 +130,47 @@ sudo python3 "$OPT_VOSK"/setup.py install
if [ $? = 0 ]; then if [ $? = 0 ]; then
sudo rm "$OPT_VOSK"/setup.py sudo rm "$OPT_VOSK"/setup.py
else else
echo "something went wrong, please check setup.py file" printwc "${Red}" "Something went wrong, please check setup.py file"
exit exit
fi fi
# Cleaning existing local directories and binary link. #--------------------------------------------------
print_title "Cleaning existing local directories and binary link."
#--------------------------------------------------
rm -rf "$HOME"/.local/nerd-dictation rm -rf "$HOME"/.local/nerd-dictation
rm -f "$HOME"/.local/bin/nerd-dictation rm -f "$HOME"/.local/bin/nerd-dictation
rm -rf "$HOME"/.config/nerd-dictation rm -rf "$HOME"/.config/nerd-dictation
# Set repo as local package. #--------------------------------------------------
print_title "Set repo as local package."
#--------------------------------------------------
cd "$HOME"/.local cd "$HOME"/.local
git clone "$NERD_DIC_GIT_REPO" git clone "$NERD_DIC_GIT_REPO"
cd nerd-dictation cd nerd-dictation
# Setup language model #--------------------------------------------------
print_title "Setup language model"
#--------------------------------------------------
wget "$VOSK_MODEL" wget "$VOSK_MODEL"
unzip "$(basename $VOSK_MODEL)" unzip "$(basename $VOSK_MODEL)"
if [ $? = 0 ]; then if [ $? = 0 ]; then
rm "$(basename $VOSK_MODEL)" rm "$(basename $VOSK_MODEL)"
else else
echo "something went wrong, please check $(basename $VOSK_MODEL) file" printwc "${Red}" "Something went wrong, please check $(basename $VOSK_MODEL) file"
exit exit
fi fi
mv "$VOSK_FOLDER" model mv "$VOSK_FOLDER" model
mkdir "$HOME"/.config/nerd-dictation mkdir "$HOME"/.config/nerd-dictation
mv model "$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 [ ! -d "$HOME"/.local/bin ] && mkdir "$HOME"/.local/bin
ln -s "$HOME"/.local/nerd-dictation/nerd-dictation "$HOME"/.local/bin ln -s "$HOME"/.local/nerd-dictation/nerd-dictation "$HOME"/.local/bin
if [ $? = 0 ]; then 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 else
echo "Something went wrong please check." printwc "${Red}" "Something went wrong please check the previous output."
fi fi