#!/usr/bin/env bash
set -e

CONFIG_PATH=/data/options.json

VOICE_REF=$(jq -r '.voice_ref' $CONFIG_PATH)
VOLUME_BOOST=$(jq -r '.volume_boost // 3.0' $CONFIG_PATH)
DEVICE=$(jq -r '.device // "cuda"' $CONFIG_PATH)
DEBUG=$(jq -r '.debug // false' $CONFIG_PATH)

echo "starting wyoming-chatterbox..."
echo "voice_ref: ${VOICE_REF}"
echo "device: ${DEVICE}"

ARGS="--uri tcp://0.0.0.0:10201 --voice-ref ${VOICE_REF} --volume-boost ${VOLUME_BOOST} --device ${DEVICE}"

if [ "${DEBUG}" = "true" ]; then
    ARGS="${ARGS} --debug"
fi

export PYTORCH_CUDA_ALLOC_CONF=expandable_segments:True

exec wyoming-chatterbox ${ARGS}
