Meatgrinder/meatgrinder.py

51 lines
1.8 KiB
Python
Raw Normal View History

2024-10-10 14:51:48 +00:00
import argparse
import os
2024-10-10 14:54:54 +00:00
import media_convert
2024-10-10 14:51:48 +00:00
import transcribe
import summarize
parser = argparse.ArgumentParser(description='Transcribe and summarize meeting recordings')
parser.add_argument('input', type=str, help='Path to the input media')
parser.add_argument('--output', type=str, help='Path to the output file, will not print result to stdout if provided')
2024-10-16 13:46:04 +00:00
parser.add_argument('--save-transcription', type=str, help='Path to save the transcription to')
parser.add_argument('--skip-summary', action='store_true', help='Do not summarize')
2024-10-10 14:51:48 +00:00
parser.add_argument('--force', action='store_true', help='Overwrite existing output file without asking')
args = parser.parse_args()
if not args.input:
print("Please provide an input file")
exit(1)
2024-10-16 13:46:04 +00:00
if args.output and args.skip_summary:
print("Cannot save output file without summarizing, ignoring --output")
if args.output and os.path.isfile(args.output) and not args.force and not args.skip_summary:
2024-10-10 14:51:48 +00:00
print("Output file already exists and will be overwritten")
if input("Continue? [y/N] ").lower() != "y":
exit(1)
2024-10-16 13:46:04 +00:00
if args.save_transcription:
if os.path.isfile(args.save_transcription) and not args.force:
print("Transcription file already exists and will be overwritten")
if input("Continue? [y/N] ").lower() != "y":
exit(1)
2024-10-10 14:51:48 +00:00
2024-10-10 14:54:54 +00:00
audio_file = media_convert.process(args.input)
2024-10-10 14:51:48 +00:00
transcription = transcribe.process(audio_file)
2024-10-16 13:47:00 +00:00
if os.path.isfile(audio_file):
os.remove(audio_file)
2024-10-16 13:46:04 +00:00
if args.save_transcription:
with open(args.save_transcription, 'w') as f:
f.write(transcription)
if not args.skip_summary:
summary = summarize.process(transcription)
if args.output:
with open(args.output, 'w') as f:
f.write(summary)
else:
print(summary)