feat: add local whisper subtitle generation
This commit is contained in:
1 parent
5228765473
commit
6a6fd347bd
17 files changed
+1041
-96
No files matched your search
@@ -0,0 +1,39 @@
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
sys.path.insert(0, str(Path(__file__).resolve().parent.parent))
|
||||
|
||||
from backend.subtitle_alignment import align_first_sentence_with_asr
|
||||
from backend.subtitle_tools import SubtitleCue
|
||||
|
||||
|
||||
class FakeAsrClient:
|
||||
def transcribe(self, audio_path):
|
||||
return {
|
||||
"text": "hello world",
|
||||
"segments": [
|
||||
{"start": 1.5, "end": 3.0, "text": "hello world"}
|
||||
],
|
||||
}
|
||||
|
||||
|
||||
def test_align_first_sentence_with_asr_uses_first_segment_start(tmp_path=None):
|
||||
video_path = Path("tests") / "tmp-video.mp4"
|
||||
video_path.write_bytes(b"fake video")
|
||||
try:
|
||||
result = align_first_sentence_with_asr(
|
||||
video_path,
|
||||
SubtitleCue("00:00:00.500", "00:00:02.000", "Hello world"),
|
||||
FakeAsrClient(),
|
||||
extract_audio=lambda source, target: target.write_bytes(b"fake wav"),
|
||||
)
|
||||
finally:
|
||||
video_path.unlink(missing_ok=True)
|
||||
|
||||
assert result.applied is True
|
||||
assert result.first_sentence_start == 1.5
|
||||
assert result.offset_seconds == 1.0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
test_align_first_sentence_with_asr_uses_first_segment_start()
|
||||
Reference in new issue
Block a user