Files
voice-to-notes/python/tests/test_transcribe.py
Josh Knapp 67ed69df00 Stream transcript segments to frontend as they are transcribed
Send each segment to the frontend immediately after transcription via
a new pipeline.segment IPC message, then send speaker assignments as a
batch pipeline.speaker_update message after diarization completes. This
lets the UI display segments progressively instead of waiting for the
entire pipeline to finish.

Changes:
- Add partial_segment_message and speaker_update_message IPC factories
- Add on_segment callback parameter to TranscribeService.transcribe()
- Emit partial segments and speaker updates from PipelineService.run()
- Add send_and_receive_with_progress to SidecarManager (Rust)
- Route pipeline.segment/speaker_update events in run_pipeline command
- Listen for streaming events in Svelte frontend (+page.svelte)
- Add tests for new message types, callback signature, and update logic

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-20 13:47:57 -07:00

70 lines
2.0 KiB
Python

"""Tests for transcription service."""
import inspect
from voice_to_notes.services.transcribe import (
SegmentResult,
TranscribeService,
TranscriptionResult,
WordResult,
result_to_payload,
)
def test_result_to_payload():
"""Test converting TranscriptionResult to IPC payload."""
result = TranscriptionResult(
segments=[
SegmentResult(
text="hello world",
start_ms=0,
end_ms=2000,
words=[
WordResult(word="hello", start_ms=0, end_ms=500, confidence=0.95),
WordResult(word="world", start_ms=600, end_ms=2000, confidence=0.92),
],
),
],
language="en",
language_probability=0.98,
duration_ms=2000,
)
payload = result_to_payload(result)
assert payload["language"] == "en"
assert payload["duration_ms"] == 2000
assert len(payload["segments"]) == 1
seg = payload["segments"][0]
assert seg["text"] == "hello world"
assert seg["start_ms"] == 0
assert seg["end_ms"] == 2000
assert len(seg["words"]) == 2
assert seg["words"][0]["word"] == "hello"
assert seg["words"][0]["confidence"] == 0.95
def test_result_to_payload_empty():
"""Test empty transcription result."""
result = TranscriptionResult()
payload = result_to_payload(result)
assert payload["segments"] == []
assert payload["language"] == ""
assert payload["duration_ms"] == 0
def test_on_segment_callback():
"""Test that on_segment callback is invoked with correct SegmentResult and index."""
callback_args = []
def mock_callback(seg: SegmentResult, index: int):
callback_args.append((seg.text, index))
# Test that passing on_segment doesn't break the function signature
# (Full integration test would require mocking WhisperModel)
service = TranscribeService()
# Verify the parameter exists by checking the signature
sig = inspect.signature(service.transcribe)
assert "on_segment" in sig.parameters