From 07ff09128e572ef91933e889719be245b4d57791 Mon Sep 17 00:00:00 2001 From: Gigi Date: Tue, 1 Apr 2025 17:06:05 +0100 Subject: [PATCH] Show subprocess output in real-time & add consistent force flag behavior - Show output from process.sh, transcribe.sh, and extract.sh in real-time when running watch.py - Add force flag support to transcribe.sh to prevent overwriting existing transcripts - Update process.sh to propagate force flag to transcribe.sh - Now force flag behavior is consistent: without -f skips existing files, with -f overwrites files - Force flag propagates through entire chain: watch -> process -> transcribe/extract --- process.sh | 2 +- src/watch_voice_memos.py | 6 +++--- transcribe.sh | 17 ++++++++++++++++- 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/process.sh b/process.sh index 1b17e28..3e35da2 100755 --- a/process.sh +++ b/process.sh @@ -37,7 +37,7 @@ echo "----------------------------------------" # Step 1: Transcribe echo "Step 1: Transcribing audio..." -./transcribe.sh "$input_file" +./transcribe.sh $force_flag "$input_file" # Check if transcription was successful if [ ! -f "$transcript_file" ]; then diff --git a/src/watch_voice_memos.py b/src/watch_voice_memos.py index ffa696f..c7661fc 100755 --- a/src/watch_voice_memos.py +++ b/src/watch_voice_memos.py @@ -81,17 +81,17 @@ def process_voice_memo(file_path: Path, force: bool = False) -> None: cmd.append('-f') cmd.append(str(file_path)) + # Run subprocess without capturing output to show it in real-time result = subprocess.run( cmd, check=True, - capture_output=True, text=True ) - logger.debug(f"Process output: {result.stdout}") logger.info(f"Successfully processed: {file_path.name}") except subprocess.CalledProcessError as e: logger.error(f"Error processing {file_path.name}: {e}") - logger.debug(f"Error output: {e.stderr}") + if e.stderr: + logger.error(f"Error output: {e.stderr}") except Exception as e: logger.error(f"Unexpected error processing {file_path.name}: {e}") diff --git a/transcribe.sh b/transcribe.sh index 71728f9..2bf629b 100755 --- a/transcribe.sh +++ b/transcribe.sh @@ -1,8 +1,17 @@ #!/bin/bash +# Parse arguments +force_flag="" +while getopts "f" opt; do + case $opt in + f) force_flag="--force" ;; + esac +done +shift $((OPTIND-1)) + # Check if a file argument was provided if [ $# -ne 1 ]; then - echo "Usage: $0 " + echo "Usage: $0 [-f] " exit 1 fi @@ -26,6 +35,12 @@ mkdir -p "$TRANSCRIPT_DIR" filename=$(basename "$input_file" .m4a) transcript_file="$TRANSCRIPT_DIR/$filename.txt" +# Check if transcript already exists +if [ -f "$transcript_file" ] && [ -z "$force_flag" ]; then + echo "Transcript already exists: $transcript_file (use -f to overwrite)" + exit 0 +fi + echo "Processing file: $input_file" echo "Transcribing audio..."