-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
77 lines (62 loc) · 2.69 KB
/
Copy pathmain.py
File metadata and controls
77 lines (62 loc) · 2.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import click
import os
import tempfile
from pathlib import Path
from dotenv import load_dotenv
import anthropic
from gscribe.recorder import record_audio
from gscribe.transcriber import TranscriptionError, transcribe
from gscribe.merger import diarized, format_transcript, single_speaker
from gscribe.models import DEFAULT_SUMMARY_MODEL, SUMMARY_MODEL_IDS
from gscribe.summarizer import summarize
load_dotenv()
@click.command()
@click.option("--output", "-o", default="meeting.md", help="출력 파일 경로")
@click.option("--lang", "-l", default="ko", help="언어 코드 (기본: ko)")
@click.option("--audio", "-a", default=None, type=click.Path(exists=True), help="기존 오디오 파일")
@click.option("--no-diarize", is_flag=True, default=False, help="화자 분리 건너뜀")
@click.option(
"--model",
"-m",
default=DEFAULT_SUMMARY_MODEL,
type=click.Choice(SUMMARY_MODEL_IDS),
help=f"회의록 생성 모델 (기본: {DEFAULT_SUMMARY_MODEL})",
)
def main(output, lang, audio, no_diarize, model):
"""회의를 녹음하고 전사·요약하여 회의록을 생성합니다."""
deepgram_key = os.environ.get("DEEPGRAM_API_KEY")
anthropic_key = os.environ.get("ANTHROPIC_API_KEY")
if not deepgram_key:
click.echo("오류: DEEPGRAM_API_KEY가 필요합니다.")
raise SystemExit(1)
if not anthropic_key:
click.echo("오류: ANTHROPIC_API_KEY가 필요합니다.")
raise SystemExit(1)
anthropic_client = anthropic.Anthropic(api_key=anthropic_key)
with tempfile.TemporaryDirectory() as tmp:
if audio:
audio_path = Path(audio)
else:
audio_path = Path(tmp) / "recording.wav"
record_audio(audio_path)
click.echo("전사 중 (화자 분리 포함)..." if not no_diarize else "전사 중...")
try:
result = transcribe(audio_path, deepgram_key, lang, diarize=not no_diarize)
except TranscriptionError as e:
# 의도된 사용자 안내(인증·오디오 형식)는 traceback 대신 메시지로.
click.echo(f"오류: {e}")
raise SystemExit(1)
if not no_diarize:
merged = diarized(result)
else:
merged = single_speaker(result)
transcript = format_transcript(merged)
click.echo("\n--- 전사 결과 ---")
click.echo(transcript)
minutes = summarize(transcript, anthropic_client, model)
output_path = Path(output)
content = f"# 회의록\n\n## 전사 내용\n\n{transcript}\n\n---\n\n{minutes}"
output_path.write_text(content, encoding="utf-8")
click.echo(f"\n회의록 저장됨: {output_path}")
if __name__ == "__main__":
main()