Files
mknotes/main.py
T
schihei f00f29ab6b Move prompts to separate files and add prompt types
- Created directory structure for prompts (system and user prompts)
- Added specialized prompts for lectures, meetings, and interviews
- Updated enhancer.py to load prompts from files
- Added --prompt-type CLI parameter to select prompt type
- Updated documentation and enhancement proposals
2025-05-22 21:28:36 +02:00

77 lines
2.8 KiB
Python

# Entry point for the mknotes audio transcription and note enhancement tool
import os
from tqdm import tqdm
from src.cli import parse_args
from src.utils import find_audio_files, ensure_directory_exists, convert_wav_to_mp3
from src.transcriber import transcribe_audio
from src.enhancer import enhance_note
def main():
args = parse_args()
input_dir = args.input_dir
output_dir = args.output_dir
model_size = args.model_size
ensure_directory_exists(output_dir)
audio_files = find_audio_files(input_dir)
if not audio_files:
print(f"No audio files found in {input_dir}.")
return
print(f"Found {len(audio_files)} audio files. Starting transcription and enhancement...")
for audio_path in tqdm(audio_files, desc="Processing files"):
base_name = os.path.splitext(os.path.basename(audio_path))[0]
txt_path = os.path.join(output_dir, base_name + ".txt")
md_path = os.path.join(output_dir, base_name + ".md")
# Skip if enhanced note already exists (unless force flag is set)
if os.path.exists(md_path) and not args.force:
print(f"Skipping {audio_path} - enhanced note already exists at {md_path}")
continue
# Check if transcription exists
if os.path.exists(txt_path) and not args.force:
print(f"Using existing transcription for {audio_path}")
with open(txt_path, "r", encoding="utf-8") as f:
transcription = f.read()
else:
# Convert WAV to MP3 if needed
path_to_transcribe = audio_path
if audio_path.lower().endswith(".wav"):
print(f"Processing WAV file: {audio_path}")
mp3_path = convert_wav_to_mp3(audio_path)
if mp3_path:
path_to_transcribe = mp3_path
else:
print(f"Warning: Failed to convert {audio_path}. Will attempt to transcribe the WAV file directly.")
# Transcribe audio
transcription = transcribe_audio(
path_to_transcribe,
txt_path,
model_size=model_size,
turbo=args.turbo
)
# Enhance note (only if md file doesn't exist or force flag is set)
if not os.path.exists(md_path) or args.force:
try:
enhanced_note = enhance_note(
transcription,
prompt_type=args.prompt_type
)
with open(md_path, "w", encoding="utf-8") as f:
f.write(enhanced_note)
except Exception as e:
print(f"Error enhancing note for {audio_path}: {e}")
print(f"Processing complete. Output saved to: {output_dir}")
if __name__ == "__main__":
main()