simple-nerd-dictation-insta.../simple-nerd-dictation-insta...

179 lines
6.0 KiB
Bash
Raw Normal View History

#!/bin/bash
#
# 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
set -e
2023-10-25 02:55:02 +00:00
# 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
2023-10-25 02:55:02 +00:00
printwc "${Yellow}" "Please don't use with root privileges, sudo will be used only when necessary!"
exit 0
fi
2023-10-25 03:04:08 +00:00
#--------------------------------------------------
print_title "Check for supported arch."
#--------------------------------------------------
if dpkg-architecture -e amd64 ;then
2023-10-25 03:04:08 +00:00
printwc "${Green}" " amd64: supported architecture.\n"
else
2023-10-25 03:04:08 +00:00
printwc "${Red}" " Warning: Only run this script on amd64 arch.\n"
exit
fi
sudo apt-get update -q2
ENGLISH_VOSK_MODEL="https://alphacephei.com/vosk/models/vosk-model-en-us-0.22-lgraph.zip"
SPANISH_VOSK_MODEL="https://alphacephei.com/vosk/models/vosk-model-small-es-0.42.zip"
FRENCH_VOSK_MODEL="https://alphacephei.com/vosk/models/vosk-model-small-fr-0.22.zip"
GERMAN_VOSK_MODEL="https://alphacephei.com/vosk/models/vosk-model-small-de-0.15.zip"
CHINESE_VOSK_MODEL="https://alphacephei.com/vosk/models/vosk-model-small-cn-0.22.zip"
NERD_DIC_GIT_REPO="https://github.com/ideasman42/nerd-dictation.git"
OPT_VOSK="/opt/vosk-python"
2023-10-25 02:55:02 +00:00
#--------------------------------------------------
2023-10-25 03:04:08 +00:00
print_title "> Vosk Model Language selection."
2023-10-25 02:55:02 +00:00
#--------------------------------------------------
PS3='Select one of the available language models to use on nerd-dictation: '
options=("English" "Spanish" "French" "German" "Chinese" "Exit")
select opt in "${options[@]}"
do
case $opt in
"English")
printf "\n > Selecting English model.\n"
VOSK_MODEL="$ENGLISH_VOSK_MODEL"
break
;;
"Spanish")
printf "\n > Selecting Spanish model.\n"
VOSK_MODEL="$SPANISH_VOSK_MODEL"
break
;;
"French")
printf "\n > Selecting French model.\n"
VOSK_MODEL="$FRENCH_VOSK_MODEL"
break
;;
"German")
printf "\n > Selecting German model.\n"
VOSK_MODEL="$GERMAN_VOSK_MODEL"
break
;;
"Chinese")
printf "\n > Selecting Chinese model.\n"
VOSK_MODEL="$CHINESE_VOSK_MODEL"
break
;;
"Exit")
printf "\n > Exit installer.\n"
exit 0
break
;;
2023-10-25 02:55:02 +00:00
*) printwc "${Yellow}" "Invalid option $REPLY, choose one number of the above.";;
esac
done
VOSK_FOLDER="$(basename $VOSK_MODEL|sed 's|.zip||')"
2023-10-25 02:55:02 +00:00
#--------------------------------------------------
print_title "Install dependencies"
#--------------------------------------------------
sudo apt-get install -y git ssh python3-setuptools pulseaudio-utils xdotool
2023-10-25 02:55:02 +00:00
#--------------------------------------------------
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
from setuptools import setup
setup(
install_requires=['vosk'],
dependency_links=[
'https://files.pythonhosted.org/packages/fc/ca/83398cfcd557360a3d7b2d732aee1c5f6999f68618d1645f38d53e14c9ff/vosk-0.3.45-py3-none-manylinux_2_12_x86_64.manylinux2010_x86_64.whl',
],
)
EOF
cd "$OPT_VOSK"
sudo python3 "$OPT_VOSK"/setup.py install
if [ $? = 0 ]; then
sudo rm "$OPT_VOSK"/setup.py
else
2023-10-25 03:04:08 +00:00
printwc "${Red}" "Something went wrong, please check setup.py file\n"
exit
fi
2023-10-25 02:55:02 +00:00
#--------------------------------------------------
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
2023-10-25 02:55:02 +00:00
#--------------------------------------------------
print_title "Set repo as local package."
#--------------------------------------------------
cd "$HOME"/.local
git clone "$NERD_DIC_GIT_REPO"
cd nerd-dictation
2023-10-25 02:55:02 +00:00
#--------------------------------------------------
print_title "Setup language model"
#--------------------------------------------------
wget "$VOSK_MODEL"
unzip "$(basename $VOSK_MODEL)"
if [ $? = 0 ]; then
rm "$(basename $VOSK_MODEL)"
else
2023-10-25 03:04:08 +00:00
printwc "${Red}" "Something went wrong, please check $(basename $VOSK_MODEL) file\n"
exit
fi
mv "$VOSK_FOLDER" model
mkdir "$HOME"/.config/nerd-dictation
mv model "$HOME"/.config/nerd-dictation/
2023-10-25 02:55:02 +00:00
#--------------------------------------------------
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
2023-10-25 03:04:08 +00:00
printwc "${Green}" "Completed script!\nPlease exit and login for nerd-dictation to be used on the terminal.\n"
else
2023-10-25 03:04:08 +00:00
printwc "${Red}" "Something went wrong please check the previous output.\n"
fi