167 lines
5.4 KiB
Bash
Executable File
167 lines
5.4 KiB
Bash
Executable File
#! /bin/bash
|
|
# Orion bot
|
|
#
|
|
# Copyright (c) 2022 Sameer Rahmani <lxsameer@gnu.org>
|
|
#
|
|
# This program is free software; you can redistribute it and/or modify
|
|
# it under the terms of the GNU General Public License as published by
|
|
# the Free Software Foundation, version 2.
|
|
#
|
|
# This program is distributed in the hope that it will be useful,
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
# GNU General Public License for more details.
|
|
#
|
|
# You should have received a copy of the GNU General Public License
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
# -----------------------------------------------------------------------------
|
|
# Commentary
|
|
# -----------------------------------------------------------------------------
|
|
# This is the builder script for the Orion project. It makes it easier to
|
|
# interact with the build system
|
|
#
|
|
# In order to define a subcommand all you need to do is to define a function
|
|
# with the following syntax:
|
|
#
|
|
# function subcommand-name() { ## DESCRIPTION
|
|
# .. subcommand body ..
|
|
# }
|
|
#
|
|
# Make sure to provid one line of DESCRIPTION for the subcommand and use two "#"
|
|
# characters to start the description following by a space. Otherwise, your
|
|
# subcommand won't be registered
|
|
|
|
set -e
|
|
|
|
# -----------------------------------------------------------------------------
|
|
# Vars & Config
|
|
# -----------------------------------------------------------------------------
|
|
|
|
command=$1
|
|
VERSION="0.1.0"
|
|
|
|
# Change the url to point to the stt native client of your platform
|
|
STT_BINARY=https://github.com/coqui-ai/STT/releases/download/v1.3.0/native_client.tflite.Linux.tar.xz
|
|
MODEL=https://coqui.gateway.scarf.sh/english/coqui/v1.0.0-huge-vocab/model.tflite
|
|
SCORER=https://coqui.gateway.scarf.sh/english/coqui/v1.0.0-huge-vocab/huge-vocabulary.scorer
|
|
|
|
ME=$(cd "$(dirname "$0")/." >/dev/null 2>&1 ; pwd -P)
|
|
|
|
export CGO_LDFLAGS=-L$ME/coqui/
|
|
export CGO_CXXFLAGS=-I$ME/coqui/
|
|
export LD_LIBRARY_PATH=$ME/coqui/:$LD_LIBRARY_PATH
|
|
|
|
default_model="$ME/models/default.tflite"
|
|
default_scorer="$ME/models/default.scorer"
|
|
|
|
# -----------------------------------------------------------------------------
|
|
# Helper functions
|
|
# -----------------------------------------------------------------------------
|
|
function fn-names() {
|
|
grep -E '^function [0-9a-zA-Z_-]+\(\) \{ ## .*$$' "$0" | sed 's/^function \([a-zA-Z0-9_-]*\)() { ## \(.*\)/\1/'
|
|
}
|
|
|
|
function info() {
|
|
if [ "$1" ]
|
|
then
|
|
echo -e "[\033[01;32mINFO\033[00m]: $1"
|
|
fi
|
|
}
|
|
|
|
function error() {
|
|
if [ "$1" ]
|
|
then
|
|
echo -e "[\033[01;31mERR\033[00m]: $1"
|
|
fi
|
|
}
|
|
|
|
function warn() {
|
|
if [ "$1" ]
|
|
then
|
|
echo -e "[\033[01;33mWARN\033[00m]: $1"
|
|
fi
|
|
}
|
|
|
|
# -----------------------------------------------------------------------------
|
|
# Subcomaands
|
|
# -----------------------------------------------------------------------------
|
|
function setup() { ## Setup the working directory and make it ready for development
|
|
info "Creating the virtual env..."
|
|
virtualenv "$ME/.venv"
|
|
# shellcheck source=.venv/bin/activate
|
|
. "$ME/.venv/bin/activate"
|
|
info "Intalling tflite runtime..."
|
|
pip3 install -r rigel/requirements.txt
|
|
pip3 install --extra-index-url https://google-coral.github.io/py-repo/ tflite_runtime
|
|
|
|
info "Downloding STT..."
|
|
wget $STT_BINARY -O nc.tar.xz
|
|
mkdir -p "$ME/coqui"
|
|
tar -Jxvf nc.tar.xz -C "$ME/coqui"
|
|
|
|
info "Installing coqui go binding..."
|
|
go mod download
|
|
|
|
info "Downloading the model..."
|
|
mkdir -p "$(dirname $default_model)"
|
|
wget "$MODEL" -O "$default_model"
|
|
|
|
info "Downloading the scorer..."
|
|
mkdir -p "$(dirname $default_scorer)"
|
|
wget "$SCORER" -O "$default_scorer"
|
|
deactivate
|
|
}
|
|
|
|
function run() { ## Setup the working directory and make it ready for development
|
|
|
|
# shellcheck source=.venv/bin/activate
|
|
. "$ME/.venv/bin/activate"
|
|
go run orion.go -model "$default_model" -scorer "$default_scorer" "$@"
|
|
deactivate
|
|
}
|
|
|
|
function rigel() { ## Run the rigel server
|
|
# shellcheck source=.venv/bin/activate
|
|
. "$ME/.venv/bin/activate"
|
|
"$ME/rigel/server.py" --env "$ME/.env" $1
|
|
deactivate
|
|
}
|
|
|
|
function help() { ## Print out this help message
|
|
echo "Commands:"
|
|
grep -E '^function [a-zA-Z0-9_-]+\(\) \{ ## .*$$' "$0" | \
|
|
sort | \
|
|
sed 's/^function \([a-zA-Z0-9_-]*\)() { ## \(.*\)/\1:\2/' | \
|
|
awk 'BEGIN {FS=":"}; {printf "\033[36m%-30s\033[0m %s\n", $1, $2}'
|
|
}
|
|
|
|
function install-openrc() { ## Install openrc service for Rigel(doesn't enable it)
|
|
# shellcheck source=.venv/bin/activate
|
|
cp "$ME/rigel/service/openrc/rigel" /tmp/rigel
|
|
sed -i "s%<root-project>%$ME%g" /tmp/rigel
|
|
sudo cp "/tmp/rigel" /etc/init.d/
|
|
sudo chmod 0755 /etc/init.d/rigel
|
|
}
|
|
|
|
# -----------------------------------------------------------------------------
|
|
# Main logic
|
|
# -----------------------------------------------------------------------------
|
|
echo -e "\nOrion Version $VERSION"
|
|
echo -e "\nCopyright (C) 2022 Sameer Rahmani <lxsameer@gnu.org>"
|
|
echo -e "Orion comes with ABSOLUTELY NO WARRANTY;"
|
|
echo -e "This is free software, and you are welcome"
|
|
echo -e "to redistribute it under certain conditions;"
|
|
echo -e "for details take a look at the LICENSE file.\n"
|
|
|
|
# Find the subcommand in the functions and run we find it.
|
|
for fn in $(fn-names); do
|
|
if [[ $fn == "$command" ]]; then
|
|
eval "$fn" "${@:2}"
|
|
exit $?
|
|
fi
|
|
done
|
|
|
|
# If we couldn't find the command print out the help message
|
|
help
|