#!/bin/bash

BASE_DIR="$HOME/Dropbox/__INBOX_RECIEVING/__AUDIO-IN"
INPUT_DIR="$BASE_DIR/_04_Final_Processed_MP3"
OUTPUT_DIR="$BASE_DIR/_05_AUTO_Transcribed"
TRANSCRIPT_DIR="$BASE_DIR/_05_AUTO_Transcribed"
LOG_FILE="$BASE_DIR/_LOGS/final_transcription_log.txt"

echo "Script starting..."
echo "Watching directory: $INPUT_DIR"
echo "Transcripts will be saved to: $OUTPUT_DIR"

# Watch for new files, excluding .DS_Store
fswatch -0 -e "\.DS_Store$" "$INPUT_DIR" | while read -d "" file; do
    echo "$(date): Processing file: $file" | tee -a "$LOG_FILE"
    
# Get filename without extension
filename=$(basename "$file")
filename_no_ext="${filename%.*}"
transcript_file="$OUTPUT_DIR/${filename_no_ext}_transcript.txt"

echo "Transcribing: $filename" | tee -a "$LOG_FILE"
if /path/to/whisper.cpp-master/build/main -m /path/to/whisper.cpp-master/models/ggml-base.en.bin -f "$file" -l en > "$transcript_file" 2>> "$LOG_FILE"; then
    echo "$(date): Successfully transcribed $filename" | tee -a "$LOG_FILE"
else
    echo "$(date): Error transcribing $filename" | tee -a "$LOG_FILE"
fi

done