]>
zdv2.bktei.com Git - BK-2020-03.git/blob - user/transcribe_whisper.sh
   2 # Usage: ./transcribe_whisper.sh 3 
   3 # Input: arg1  CUDA graphics card number (zero-indexed) 
   5 # Depends: whisper ( https://github.com/openai/whisper ) 
   7 yell
() { echo "$0: $*" >&2; } # print script path and all args to stderr 
   8 die
() { yell 
"$*"; exit 111; } # same as yell() but non-zero exit status 
   9 must
() { "$@" || die 
"cannot $*"; } # runs args as command, reports args if command fails 
  11     # Desc: Checks if arg is integer 
  14     # Output: - return code 0 (if arg is integer) 
  15     #         - return code 1 (if arg is not integer) 
  16     # Example: if ! checkInt $arg; then echo "not int"; fi; 
  21     if [[ $# -ne 1 ]]; then 
  22         die 
"ERROR:Invalid number of arguments:$#"; 
  25     RETEST1
='^[0-9]+$'; # Regular Expression to test 
  26     if [[ ! "$1" =~ 
$RETEST1 ]] ; then 
  32     #===Determine function return code=== 
  33     if [ "$returnState" = "true" ]; then 
  38 } # Checks if arg is integer 
  41     if ! checkInt 
"$cuda_num"; then die 
"FATAL:No graphics card selected."; fi; 
  42     while read -r line
; do 
  43         echo "STATUS:Processing:$line" 1>&2; 
  45         dir_out
="$(dirname "$line"; )"; 
  47         #declare -p line dir_out ftmp; # debug 
  48         if [[ ! -f "$ftmp" ]] && \
 
  49                [[ ! -f "${line%.*}".srt 
]] && \
 
  50                [[ ! -f "${line%.*}".vtt 
]] && \
 
  51                [[ ! -f "${line%.*}".txt 
]] && \
 
  52                [[ ! -f "${line%.*}".tsv 
]] && \
 
  53                [[ ! -f "${line%.*}".json 
]]; then 
  55             yell 
"STATUS:No conflicts detected."; 
  57             yell 
"STATUS:Skipping:$line"; 
  63                 --output_dir "$dir_out" \
 
  65                 --device cuda
:"$cuda_num" && \
 
  67                 echo "STATUS:$SECONDS:Finished:$line" 1>&2; 
  68                 rm "$ftmp"; # remove .tmp file 
  70     done < <(find . 
-type f 
-name "*.mp3" | shuf 
)