From 1deac7e514800559fc8b8bdd7cf3db083d8d5f9e Mon Sep 17 00:00:00 2001 From: Steven Baltakatei Sandoval Date: Mon, 6 May 2024 04:37:41 +0000 Subject: [PATCH 1/1] feat(user/transcribe_whisper.sh):Apply to various media files --- user/transcribe_whisper.sh | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) mode change 100644 => 100755 user/transcribe_whisper.sh diff --git a/user/transcribe_whisper.sh b/user/transcribe_whisper.sh old mode 100644 new mode 100755 index a6fdad5..68756c7 --- a/user/transcribe_whisper.sh +++ b/user/transcribe_whisper.sh @@ -1,9 +1,15 @@ #!/bin/bash +# Desc: Runs OpenAI Whisper on working directory media files # Usage: ./transcribe_whisper.sh 3 # Input: arg1 CUDA graphics card number (zero-indexed) -# Version: 0.0.1 +# Version: 0.1.0 # Depends: whisper ( https://github.com/openai/whisper ) +# Find settings +firegex=".+\(aac\|aif\|aiff\|flac\|m4a\|m4b\|mkv\|mp3\|mp4\|ogg\|opus\|wav\)$"; # update according to `find . -type f | grep -Eo "\.([[:alnum:]])+$" | sort -u` +fsize="10k"; # default: minimum "10k" +fdepth="10"; # find depth + yell() { echo "$0: $*" >&2; } # print script path and all args to stderr die() { yell "$*"; exit 111; } # same as yell() but non-zero exit status must() { "$@" || die "cannot $*"; } # runs args as command, reports args if command fails @@ -36,8 +42,21 @@ checkInt() { return 1; fi; } # Checks if arg is integer +find_flist() { + # Desc: print file list to stdout via `find` using script parameters + # Input: arg1: path to dir + # var: fdepth find depth + # var: firegex pattern find iregex + # var: fsize find size + if [[ ! -d "$1" ]]; then return 1; fi; + must find "$1" -maxdepth "$fdepth" -type f -iregex "$firegex" -size +"$fsize"; +}; # print file list to stdout from dir with script parameters main() { + # Input: var: fdepth (find_flist) find depth + # var: firegex (find_flist) pattern find iregex + # var: fsize (find_flist) find size cuda_num="$1"; + dir_in="$(pwd)"; if ! checkInt "$cuda_num"; then die "FATAL:No graphics card selected."; fi; while read -r line; do echo "STATUS:Processing:$line" 1>&2; @@ -67,8 +86,9 @@ main() { echo "STATUS:$SECONDS:Finished:$line" 1>&2; rm "$ftmp"; # remove .tmp file ); - done < <(find . -type f -name "*.mp3" | shuf ) + done < <(find_flist "$dir_in"); }; # main program +export -f yell die must find_flist; main "$@"; -- 2.30.2