transcribe-matrix-live

A fork for matrix-live transcription@home by fyyd.de
git clone git://archive.git.mtrnord.blog/MTRNord/transcribe-matrix-live.git
Log | Files | Refs | README

commit 8799fa24915359d4d8c3db6035040ed73f7f6b9b
parent 470505526b4e22dc5f642c63d2414ad033cf8653
Author: MTRNord <mtrnord1@gmail.com>
Date:   Thu, 26 Jan 2023 23:56:41 +0100

Run shellcheck

Diffstat:
Mtranscribe.sh | 47++++++++++++++++++++---------------------------
1 file changed, 20 insertions(+), 27 deletions(-)

diff --git a/transcribe.sh b/transcribe.sh @@ -1,7 +1,5 @@ #!/bin/bash -SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) - if [ -f ./trancribe.cfg ] then source "./trancribe.cfg" @@ -17,7 +15,7 @@ trap ctrl_c INT trap stop EXIT function stop { - rm $PIDFILE + rm "$PIDFILE" } function ctrl_c() { @@ -26,31 +24,28 @@ function ctrl_c() { echo "STOPPING..." echo "bye bye" echo "------------------------------" - rm -f $PIDFILE + rm -f "$PIDFILE" exit } pid() { - if [ -f $PIDFILE ] + if [ -f "$PIDFILE" ] then - PID=$(cat $PIDFILE) - ps -p $PID > /dev/null 2>&1 - if [ $? -eq 0 ] + PID=$(cat "$PIDFILE") + if ps -p "$PID" > /dev/null 2>&1; then echo "Process already running" exit 1 else ## Process not found assume not running - echo $$ > $PIDFILE - if [ $? -ne 0 ] + if ! echo $$ > "$PIDFILE"; then echo "Could not create PID file" exit 1 fi fi else - echo $$ > $PIDFILE - if [ $? -ne 0 ] + if ! echo $$ > "$PIDFILE"; then echo "Could not create PID file" exit 1 @@ -61,7 +56,7 @@ pid() { pid echo "Starting engines! Let's transcribe some episodes" -pushd whisper.cpp +pushd whisper.cpp || exit #------------------------------------------------------------------------------------ # get data for one episode to transcribe from matrix youtube @@ -69,19 +64,19 @@ pushd whisper.cpp echo "getting data from youtube" mkdir -p ./playlist -pushd ./playlist +pushd ./playlist || exit PLAYLIST_URL="https://www.youtube.com/playlist?list=PLl5dnxRMP1hXBHqokHol6DTVIbnsf57Mr" yt-dlp "${PLAYLIST_URL}" -x --audio-format wav --audio-quality 0 -o "%(id)s.%(ext)s" -popd +popd || exit while : do # exit if nothing to do - if ! [ -n "$(find "./playlist/" -maxdepth 1 -type f 2>/dev/null)" ]; + if [ -z "$(find "./playlist/" -maxdepth 1 -type f 2>/dev/null)" ]; then echo "nothing to transcribe. exit!" exit 0; @@ -107,28 +102,26 @@ do mv "${next_file}" "./${FILENAME}_orig" ffmpeg -y -i "./${FILENAME}_orig" -acodec pcm_s16le -ac 1 -ar 16000 "./${FILENAME}" >/dev/null 2>/dev/null - rm ./${FILENAME}_orig + rm "./${FILENAME}_orig" DURATION=$(ffprobe -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 "./${FILENAME}" 2>&1) echo "start working on episode ${FILENAME}, duration ${DURATION} seconds" - START=`date +%s` + START=$(date +%s) echo "starting whisper" - nice -n 18 ./main -su -m "models/ggml-${MODEL}.bin" -t $THREADS -l en -ovtt "./${FILENAME}" >/dev/null 2>/dev/null - if [ $? -ne 0 ] + if ! nice -n 18 ./main -su -m "models/ggml-${MODEL}.bin" -t "$THREADS" -l en -ovtt "./${FILENAME}" >/dev/null 2>/dev/null; then echo "error transcribing" continue - fi - END=`date +%s` - TOOK=$(($END-$START)) + END=$(date +%s) + TOOK=$((END-START)) echo -n "Rate: " - printf "%.2f" $(echo "$DURATION/$TOOK" | bc -l) + printf "%.2f" "$(echo "$DURATION/$TOOK" | bc -l)" echo "x" rm "./${FILENAME}" @@ -137,7 +130,7 @@ do mv "./${FILENAME}.vtt" "./output/${FILENAME}.vtt" if [ -f ~/.trancribe-stop ]; then - rm "~/.trancribe-stop" + rm "$HOME/.trancribe-stop" echo "stopping hard" exit fi @@ -147,6 +140,6 @@ do done -popd +popd || exit -rm $PIDFILE +rm "$PIDFILE"