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