#!/bin/bash # generate_report.sh — Simplified pipeline: transcription + merge + PDF # Usage: ./generate_report.sh set -euo pipefail SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" if [ $# -lt 1 ]; then echo "Usage: $0 " exit 1 fi MEETING_DIR="$SCRIPT_DIR/$1" TRANSCRIPTION_DIR="$MEETING_DIR/transcription" DIAGRAMS_DIR="$MEETING_DIR/diagrams" if [ ! -d "$MEETING_DIR" ]; then echo "Error: Meeting directory not found: $MEETING_DIR" exit 1 fi # ------------------------------------------------------------ # Step 1: Transcription (skip if already done) # ------------------------------------------------------------ if [ -d "$TRANSCRIPTION_DIR" ] && [ -f "$TRANSCRIPTION_DIR/plain_text.txt" ]; then echo "[1/3] Transcription already exists, skipping." else echo "[1/3] Running transcription..." bash "$SCRIPT_DIR/transcribe.sh" "$MEETING_DIR" fi # ------------------------------------------------------------ # Step 2: Merge transcriptions (if both saramonic and h2n exist) # ------------------------------------------------------------ echo "[2/3] Merging transcriptions where possible..." if [ -f "$TRANSCRIPTION_DIR/saramonic.json" ] && [ -f "$TRANSCRIPTION_DIR/h2n_xy.json" ]; then echo " Merging saramonic (primary) + h2n_xy (secondary) → merged.json" python3 "$SCRIPT_DIR/merge_transcriptions.py" \ "$TRANSCRIPTION_DIR/saramonic.json" \ "$TRANSCRIPTION_DIR/h2n_xy.json" \ "$MEETING_DIR" elif [ -f "$TRANSCRIPTION_DIR/saramonic.json" ] && [ -f "$TRANSCRIPTION_DIR/h2n_ms.json" ]; then echo " Merging saramonic (primary) + h2n_ms (secondary) → merged.json" python3 "$SCRIPT_DIR/merge_transcriptions.py" \ "$TRANSCRIPTION_DIR/saramonic.json" \ "$TRANSCRIPTION_DIR/h2n_ms.json" \ "$MEETING_DIR" else echo " Only one transcription source found or none — copying plain text to merged_plain.txt" # Try to find any existing plain text PLAIN_SRC=$(find "$TRANSCRIPTION_DIR" -name "*_plain.txt" | head -1) if [ -n "$PLAIN_SRC" ]; then cp "$PLAIN_SRC" "$MEETING_DIR/merged_plain.txt" echo " Copied $PLAIN_SRC -> merged_plain.txt" else echo " No plain text found yet — will be created after transcription finishes." fi fi # ------------------------------------------------------------ # Step 3: Generate PDF from report.md (if exists) # ------------------------------------------------------------ echo "[3/3] Generating PDF from report.md (if present)..." REPORT_MD="$MEETING_DIR/report.md" REPORT_PDF="$MEETING_DIR/report.pdf" if [ ! -f "$REPORT_MD" ]; then echo " No report.md found. Agent must write this file first." echo " After writing the report, run: pandoc $REPORT_MD -o $REPORT_PDF ..." exit 0 fi cd "$MEETING_DIR" pandoc report.md -o report.pdf \ --pdf-engine=xelatex \ -V mainfont="DejaVu Serif" \ -V sansfont="DejaVu Sans" \ -V monofont="DejaVu Sans Mono" \ -V geometry:margin=2cm \ -V fontsize=11pt \ -V lang=ru \ --highlight-style=tango PDF_SIZE=$(du -h "$REPORT_PDF" | cut -f1) echo "" echo "Done! Report: $REPORT_PDF ($PDF_SIZE)"