# shellcheck shell=dash

xrc:mod:lib     whisper

___x_cmd_whisper_online(){
    local X_help_cmd=; X_help_cmd='___x_cmd help -m whisper online' help:arg:parse

    # Check if whisper-streaming is installed
    if ! ___x_cmd_hascmd python3; then
        ___x_cmd env try python
    fi

    # Check and install whisper-streaming if needed

    # TODO: using uv to install .
    if ! python3 -c "import whisperstream" 2>/dev/null; then
        whisper:info "Installing whisper-streaming..."
        python3 -m pip install whisper-streaming --quiet 2>/dev/null || python3 -m pip install git+https://github.com/ufal/whisper_streaming.git --quiet || {
            whisper:error "Failed to install whisper-streaming"
            return 1
        }
    fi

    # Run whisper_online.py with all arguments
    python3 -m whisperstream "$@"
}
