Last active
February 15, 2025 01:42
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 $@ |
To use:
- Download the file and rename to
whisperx
- Move the file to
~/.local/bin/
- Run
chmod a+x ~/.local/bin/whisperx
to make it executable - Add
~/.local/bin
to your path - 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
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