68756c74085f9fb88a65fc04effd328932940035
2 # Desc: Runs OpenAI Whisper on working directory media files
3 # Usage: ./transcribe_whisper.sh 3
4 # Input: arg1 CUDA graphics card number (zero-indexed)
6 # Depends: whisper ( https://github.com/openai/whisper )
9 firegex
=".+\(aac\|aif\|aiff\|flac\|m4a\|m4b\|mkv\|mp3\|mp4\|ogg\|opus\|wav\)$"; # update according to `find . -type f | grep -Eo "\.([[:alnum:]])+$" | sort -u`
10 fsize
="10k"; # default: minimum "10k"
11 fdepth
="10"; # find depth
13 yell
() { echo "$0: $*" >&2; } # print script path and all args to stderr
14 die
() { yell
"$*"; exit 111; } # same as yell() but non-zero exit status
15 must
() { "$@" || die
"cannot $*"; } # runs args as command, reports args if command fails
17 # Desc: Checks if arg is integer
20 # Output: - return code 0 (if arg is integer)
21 # - return code 1 (if arg is not integer)
22 # Example: if ! checkInt $arg; then echo "not int"; fi;
27 if [[ $# -ne 1 ]]; then
28 die
"ERROR:Invalid number of arguments:$#";
31 RETEST1
='^[0-9]+$'; # Regular Expression to test
32 if [[ ! "$1" =~
$RETEST1 ]] ; then
38 #===Determine function return code===
39 if [ "$returnState" = "true" ]; then
44 } # Checks if arg is integer
46 # Desc: print file list to stdout via `find` using script parameters
47 # Input: arg1: path to dir
48 # var: fdepth find depth
49 # var: firegex pattern find iregex
50 # var: fsize find size
51 if [[ ! -d "$1" ]]; then return 1; fi;
52 must
find "$1" -maxdepth "$fdepth" -type f
-iregex "$firegex" -size +"$fsize";
53 }; # print file list to stdout from dir with script parameters
55 # Input: var: fdepth (find_flist) find depth
56 # var: firegex (find_flist) pattern find iregex
57 # var: fsize (find_flist) find size
60 if ! checkInt
"$cuda_num"; then die
"FATAL:No graphics card selected."; fi;
61 while read -r line
; do
62 echo "STATUS:Processing:$line" 1>&2;
64 dir_out
="$(dirname "$line"; )";
66 #declare -p line dir_out ftmp; # debug
67 if [[ ! -f "$ftmp" ]] && \
68 [[ ! -f "${line%.*}".srt
]] && \
69 [[ ! -f "${line%.*}".vtt
]] && \
70 [[ ! -f "${line%.*}".txt
]] && \
71 [[ ! -f "${line%.*}".tsv
]] && \
72 [[ ! -f "${line%.*}".json
]]; then
74 yell
"STATUS:No conflicts detected.";
76 yell
"STATUS:Skipping:$line";
82 --output_dir "$dir_out" \
84 --device cuda
:"$cuda_num" && \
86 echo "STATUS:$SECONDS:Finished:$line" 1>&2;
87 rm "$ftmp"; # remove .tmp file
89 done < <(find_flist
"$dir_in");
91 export -f yell die must find_flist
;