fix(v3): code review 5개 이슈 수정

- korean_preprocessor: 발음 사전 176 → 206개 (200+ 달성)
- video_engine: SoraEngine 완전 제거 (2026-03-24 서비스 종료)
- smart_video_router: veo3/seedance2 빈 문자열 반환 → ffmpeg_slides 폴백
- cli/init: gemini_web 서비스 설정 질문 추가 (user_profile 일치)
- caption_renderer, tts_engine, video_assembler: --test 스탠드얼론 블록 추가

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
sinmb79
2026-03-29 16:14:51 +09:00
parent 6571afc982
commit 66be55ba8a
7 changed files with 198 additions and 21 deletions
+54
View File
@@ -375,4 +375,58 @@ def render_captions(
ass_content = header + '\n'.join(events) + '\n'
ass_path.write_text(ass_content, encoding='utf-8-sig') # BOM for Windows compatibility
logger.info(f'ASS 자막 생성: {ass_path.name} ({len(timestamps)}단어, {len(lines)}라인)')
# ── Standalone test ──────────────────────────────────────────────
if __name__ == '__main__':
import sys
import tempfile
from pathlib import Path
if '--test' not in sys.argv:
print("사용법: python -m bots.shorts.caption_renderer --test")
sys.exit(0)
print("=== Caption Renderer Test ===")
# Test smart_line_break
test_texts = [
("AI를 활용한 자동화 방법입니다", 18),
("단 3가지만 알면 됩니다", 12),
]
print("\n[1] smart_line_break:")
for text, max_c in test_texts:
lines = smart_line_break(text, max_c)
print(f" 입력: {text!r}")
print(f" 결과: {lines}")
# Test template lookup
print("\n[2] get_template_for_corner:")
for corner in ['쉬운세상', '숨은보물', '팩트체크', '없는코너']:
tpl = get_template_for_corner(corner)
print(f" {corner}: font_size={tpl.get('font_size')}, animation={tpl.get('animation')}")
# Test render_captions with dummy timestamps
print("\n[3] render_captions (dry-run):")
sample_timestamps = [
{'word': '이거', 'start': 0.0, 'end': 0.3},
{'word': '모르면', 'start': 0.4, 'end': 0.8},
{'word': '손해입니다', 'start': 0.9, 'end': 1.5},
]
sample_script = {'hook': '이거 모르면 손해입니다'}
with tempfile.TemporaryDirectory() as tmpdir:
out = Path(tmpdir) / 'test.ass'
render_captions(
timestamps=sample_timestamps,
script=sample_script,
output_path=out,
corner='쉬운세상',
)
exists = out.exists()
size = out.stat().st_size if exists else 0
print(f" ASS 파일 생성: {exists}, 크기: {size}bytes")
assert exists and size > 0, "ASS 파일 생성 실패"
print("\n✅ 모든 테스트 통과")
return ass_path
+52
View File
@@ -525,3 +525,55 @@ def generate_tts(
def load_timestamps(ts_path: Path) -> list[dict]:
"""저장된 타임스탬프 JSON 로드."""
return json.loads(ts_path.read_text(encoding='utf-8'))
# ── Standalone test ──────────────────────────────────────────────
if __name__ == '__main__':
import sys
import tempfile
from pathlib import Path
if '--test' not in sys.argv:
print("사용법: python -m bots.shorts.tts_engine --test")
sys.exit(0)
print("=== TTS Engine Test ===")
# Test SmartTTSRouter initialization
print("\n[1] SmartTTSRouter 초기화:")
router = SmartTTSRouter({'budget': 'free'})
print(f" budget: {router.budget}")
engine = router.select(text_length=100)
print(f" select(100chars) → {engine}")
assert isinstance(engine, str) and engine, "엔진 선택 실패"
# Test with medium budget (no API keys → falls back to free engine)
router_med = SmartTTSRouter({'budget': 'medium'})
engine_med = router_med.select(text_length=500)
print(f" medium budget select(500chars) → {engine_med}")
assert isinstance(engine_med, str) and engine_med, "medium 엔진 선택 실패"
# Test usage recording + over-limit detection
print("\n[2] 사용량 제한 로직:")
router3 = SmartTTSRouter({'budget': 'free'})
router3.record_usage('elevenlabs', 9000) # near limit
over = router3._is_over_limit('elevenlabs', 900) # 9000+900 > 8000 threshold
print(f" elevenlabs 9000자 기록 후 900자 추가 → 한도 초과: {over}")
assert over, "한도 초과 감지 실패"
# Test Edge TTS (always-available free engine) with short text
print("\n[3] Edge TTS 음성 생성 (네트워크 필요):")
with tempfile.TemporaryDirectory() as tmpdir:
try:
wav, timestamps = generate_tts(
script={'hook': '테스트입니다', 'body': [], 'closer': ''},
output_dir=Path(tmpdir),
timestamp='test_20260329',
)
print(f" WAV 생성: {wav.exists()}, 타임스탬프: {len(timestamps)}단어")
assert wav.exists(), "WAV 파일 생성 실패"
except Exception as e:
print(f" [경고] TTS 실패 (네트워크/의존성 없을 수 있음): {e}")
print("\n✅ 모든 테스트 통과")
+51
View File
@@ -628,3 +628,54 @@ class ResilientAssembler:
finally:
if tmp_cleanup and work_dir.exists():
shutil.rmtree(work_dir, ignore_errors=True)
# ── Standalone test ──────────────────────────────────────────────
if __name__ == '__main__':
import sys
if '--test' not in sys.argv:
print("사용법: python -m bots.shorts.video_assembler --test")
sys.exit(0)
print("=== Video Assembler Test ===")
# Test GPU encoder detection
print("\n[1] GPU 인코더 자동 감지:")
ffmpeg_bin = _get_ffmpeg()
encoder = _detect_gpu_encoder(ffmpeg_bin)
print(f" 감지된 인코더: {encoder}")
assert encoder in ('h264_nvenc', 'h264_amf', 'h264_qsv', 'libx264'), \
f"알 수 없는 인코더: {encoder}"
# Test ResilientAssembler encoder caching
print("\n[2] ResilientAssembler 초기화 + 인코더 캐싱:")
assembler = ResilientAssembler()
enc1 = assembler._get_encoder()
enc2 = assembler._get_encoder()
print(f" 인코더: {enc1}")
assert enc1 == enc2, "캐시 불일치"
assert assembler._encoder is not None, "캐시 저장 실패"
# Test duration helpers
print("\n[3] 유틸 함수:")
# WAV duration (requires existing file — skip if not present)
try:
import tempfile, wave
with tempfile.NamedTemporaryFile(suffix='.wav', delete=False) as tmp:
tmp_path = Path(tmp.name)
# Write minimal valid WAV (1s silence at 44100Hz mono)
with wave.open(str(tmp_path), 'w') as wf:
wf.setnchannels(1)
wf.setsampwidth(2)
wf.setframerate(44100)
wf.writeframes(b'\x00\x00' * 44100)
dur = _get_wav_duration(tmp_path)
print(f" WAV 1초 테스트: duration={dur:.2f}s")
assert abs(dur - 1.0) < 0.1, f"WAV 길이 오류: {dur}"
tmp_path.unlink(missing_ok=True)
except Exception as e:
print(f" [경고] WAV 테스트 건너뜀: {e}")
print("\n✅ 모든 테스트 통과")