Skip to content

Instantly share code, notes, and snippets.

@alexispurslane
Last active February 15, 2025 01:42
Show Gist options
  • Save alexispurslane/f5fd76b580b155bfcce3d1a67224a586 to your computer and use it in GitHub Desktop.
Save alexispurslane/f5fd76b580b155bfcce3d1a67224a586 to your computer and use it in GitHub Desktop.
A quick and dirty script to let you run a containerized version of WhisperX on any posix system without having to go through the hassle of setting up CUDNN and Python yourself.
#!/bin/bash
set -euo pipefail
original_location=$(pwd)
command=podman
command_args="run --gpus all -it -v ".:/app" --replace --name whisperx --pull=newer ghcr.io/jim60105/whisperx:base-en --" # might need to change for docker, hence the variable
filename=${@: -1}
basename=$(basename ${filename})
array=( $@ )
len=${#array[@]}
args=${array[@]:0:$len-1}
respect_stdout=0
for arg in "$args"
do
case $arg in
(--respect-stdout)
respect_stdout=1
shift
;;
(*)
;;
esac
done
stdout_aware_echo() {
if [ "$respect_stdout" -eq "0" ]
then
echo -e $@
fi
}
stdout_aware_echo "\033[34m _ ____ _ _ __\n| | / / /_ (_)________ ___ _____ | |/ /\n| | /| / / __ \/ / ___/ __ \/ _ \/ ___/ | / \n| |/ |/ / / / / (__ ) /_/ / __/ / / | \n|__/|__/_/ /_/_/____/ .___/\___/_/ /_/|_| \n /_/ Auto-Runner v0.1 \033[0m\n\n\n\nWelcome to the \033[36mWhisperX\033[0m auto-runner script!\n\nPlease hang tight!\n\n"
handle_selinux() {
stdout_aware_echo "Checking preconditions...\n"
if [ $(getenforce) == "Enforcing" ]; then
stdout_aware_echo "\033[31m🚨 Error:\033[0m SELinux seems to be enabled.\n\n\033[31mThis script needs access to your files,\033[0m but SELinux is blocking it. \033[31mPlease disable SELinux,\033[0m following these instructions: \033[36m\n\nπŸ”— <https://www.tecmint.com/disable-selinux-in-centos-rhel-fedora/>\033[0m"
else
stdout_aware_echo "βœ… SELinux disabled."
fi
if command -v podman 2>&1 >/dev/null
then
command=podman
stdout_aware_echo "βœ… Podman available."
elif command -v docker 2>&1 >/dev/null
then
command=docker
stdout_aware_echo "βœ… Docker available."
else
stdout_aware_echo "\033[31m🚨 Error:\033[0m A container runtime does not seem to be installed.\n\n\033[31mThis script needs either Podman or Docker in order to run its container,\033[0m but neither seems to be installed. \033[31mPlease install Podman,\033[0m following these instructions: \033[36m\n\nπŸ”— <https://podman.io/docs/installation>\033[0m\033[36m\nπŸ”— <https://docs.docker.com/engine/install>\033[0m"
exit 1
fi
if [ $len -lt 1 ]; then
stdout_aware_echo "\n\033[31m🚨 Error:\033[0m πŸ“‚ \033[31mYou have not provided at least an audio file.\033[0m\nWhisperX requires an audio file to do its work."
exit 1
fi
if [ ! -e "$filename" ]; then
stdout_aware_echo "\n\033[31m🚨 Error:\033[0m πŸ“‚ The audio file you have provided \033[31mdoesn't exist.\033[0m\nPlease check the path and try again."
exit 1
fi
stdout_aware_echo ""
}
handle_environment() {
stdout_aware_echo "Creating environment in \033[36m~/.stt/\033[0m...\n"
mkdir -p ~/.stt/
rm -rf ~/.stt/*
stdout_aware_echo "\033[32mπŸ’‘ Note:\033[0m πŸ“‚ Relocating provided file: \033[36m${@: -1}\033[0m\n"
cp ${@: -1} ~/.stt/
chmod -R a+rwx ~/.stt/
cd ~/.stt/
stdout_aware_echo ""
}
run_whisperx() {
stdout_aware_echo "Running \033[36mWhisperX\033[0m...\n"
stdout_aware_echo "\033[32mπŸ’‘ Note:\033[0m πŸ’» Provided arguments: \033[36m$( echo "$args" | sed -z "s/--respect-stdout//" ) $args $basename \033[0m\n"
if [ "$respect_stdout" -eq "1" ]
then
$command $command_args 2>&1 >/dev/null $( echo "$args" | sed -z "s/--respect-stdout//" ) $basename 2>&1 >/dev/null
cat ~/.stt/${basename%.*}.txt
else
time $command $command_args $args $basename
fi
mv -f ~/.stt/${basename%.*}.* $original_location/
}
main() {
handle_selinux
handle_environment $@
if [ "$respect_stdout" -eq "0" ]
then
run_whisperx $@ &
PID=$!
while [ -d /proc/$PID ]
do
for X in 'β ‹' 'β ™' 'β Ή' 'β Έ' 'β Ό' 'β ΄'
do
echo -en "\b\b\b\b$X"
sleep 0.1
done
done
else
run_whisperx $@
fi
}
main $@
@alexispurslane
Copy link
Author

alexispurslane commented Feb 14, 2025

by quick and dirty here I mean it has error checking for its dependencies, and links you to instructions on how to fix errors, beautiful output and instructions, a loading spinner that only runs while it's actually working, and is idempotently self-installing and self contained.

so not quick and dirty at all

@alexispurslane
Copy link
Author

To use:

  1. Download the file and rename to whisperx
  2. Move the file to ~/.local/bin/
  3. Run chmod a+x ~/.local/bin/whisperx to make it executable
  4. Add ~/.local/bin to your path
  5. Run whisperx [options] [your file] on the command line (ALWAYS PUT THE FILE LAST)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment