Skip to content

Instantly share code, notes, and snippets.

@mikejgray
Created May 15, 2024 16:27
Show Gist options
  • Save mikejgray/a7067743a3c50ed74f05a401fa6bb9ce to your computer and use it in GitHub Desktop.
Save mikejgray/a7067743a3c50ed74f05a401fa6bb9ce to your computer and use it in GitHub Desktop.
FasterWhisper STT Server Script
#!/bin/bash
set -e
IP=$(hostname -I | cut -d' ' -f1)
cd ~ || echo "No home directory for this user, please install with a user that has a home directory." || exit 1
PIP=""
if command -v pip >/dev/null 2>&1; then
PIP="pip"
fi
if command -v pip3 >/dev/null 2>&1; then
PIP="pip3"
fi
if command -v python -m pip >/dev/null 2>&1; then
PIP="python -m pip"
fi
if command -v python3 -m pip >/dev/null 2>&1; then
PIP="python3 -m pip"
fi
if [ -z "$PIP" ]; then
echo >&2 "FasterWhisper STT requires pip but it's not available. Please install it before running this script."
exit 1
fi
echo "********************************************************************************"
echo "Making sure we can create a Python virtual environment..."
sudo apt install python3.11-venv
echo "********************************************************************************"
echo "Creating virtual environment at ~/STT_venv"
python3.11 -m venv STT_venv
source ~/STT_venv/bin/activate
echo "********************************************************************************"
echo "Installing STT requirements"
pip install --upgrade pip wheel
pip install --pre ovos-stt-http-server ovos-stt-plugin-fasterwhisper "ovos-utils>0.0.38"
echo "********************************************************************************"
echo "Configuring STT with default medium.en model. You can change this later by editing ~/.config/mycroft/mycroft.conf"
echo "Alternate model options can be found at https://github.com/OpenVoiceOS/ovos-stt-plugin-fasterwhisper/"
echo ""
mkdir -p ~/.config/mycroft
echo "********************************************************************************"
echo "Backing up any existing mycroft.conf to ~/.config/mycroft/mycroft.conf.bak"
echo ""
# If the file exists, make a backup copy
if [ -f ~/.config/mycroft/mycroft.conf ]; then
cp ~/.config/mycroft/mycroft.conf ~/.config/mycroft/mycroft.conf.bak
fi
cat <<EOF > ~/.config/mycroft/mycroft.conf
{
"stt": {
"module": "ovos-stt-plugin-fasterwhisper",
"ovos-stt-plugin-fasterwhisper": {
"model": "medium.en",
"use_cuda": false
}
}
}
EOF
echo "********************************************************************************"
echo "STT installed, you can now start the server with:"
echo "/home/$USER/STT_venv/bin/ovos-stt-server --engine ovos-stt-plugin-fasterwhisper --host $IP"
echo ""
# Give optional instructions for systemd service
echo "If you want to run this as a service, you can use the following systemd unit file:"
echo ""
cat <<EOF > ~/ovos-stt-server.service
[Unit]
Description=OVOS FasterWhisper STT Server
After=network.target
[Service]
Type=simple
User=$USER
ExecStart=/home/$USER/STT_venv/bin/ovos-stt-server --engine ovos-stt-plugin-fasterwhisper --host $IP
Restart=on-failure
[Install]
WantedBy=multi-user.target
EOF
cat ~/ovos-stt-server.service
echo ""
echo "You can set this up as a long-running service with:"
echo "********************************************************************************"
echo "sudo cp ~/ovos-stt-server.service /etc/systemd/system/ovos-stt-server.service"
echo "sudo systemctl daemon-reload"
echo "sudo systemctl enable ovos-stt-server.service"
echo "sudo systemctl start ovos-stt-server.service"
echo "********************************************************************************"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment