Remove progress throttle so every segment emits a progress update
Previously, progress messages were only sent every 5th segment due to a `segment_count % 5` guard. This made the UI feel unresponsive for short recordings with few segments. Now every segment emits a progress update with a more descriptive message including the segment number and audio percentage. Adds a test verifying that all 8 mock segments produce progress messages, not just every 5th. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -49,3 +49,57 @@ def test_result_to_payload_empty():
|
|||||||
assert payload["segments"] == []
|
assert payload["segments"] == []
|
||||||
assert payload["language"] == ""
|
assert payload["language"] == ""
|
||||||
assert payload["duration_ms"] == 0
|
assert payload["duration_ms"] == 0
|
||||||
|
|
||||||
|
|
||||||
|
def test_progress_every_segment(monkeypatch):
|
||||||
|
"""Verify a progress message is sent for every segment, not just every 5th."""
|
||||||
|
from unittest.mock import MagicMock, patch
|
||||||
|
from voice_to_notes.services.transcribe import TranscribeService
|
||||||
|
|
||||||
|
# Mock WhisperModel
|
||||||
|
mock_model = MagicMock()
|
||||||
|
|
||||||
|
# Create mock segments (8 of them to test > 5)
|
||||||
|
mock_segments = []
|
||||||
|
for i in range(8):
|
||||||
|
seg = MagicMock()
|
||||||
|
seg.start = i * 1.0
|
||||||
|
seg.end = (i + 1) * 1.0
|
||||||
|
seg.text = f"Segment {i}"
|
||||||
|
seg.words = []
|
||||||
|
mock_segments.append(seg)
|
||||||
|
|
||||||
|
# Mock info object
|
||||||
|
mock_info = MagicMock()
|
||||||
|
mock_info.language = "en"
|
||||||
|
mock_info.language_probability = 0.99
|
||||||
|
mock_info.duration = 8.0
|
||||||
|
|
||||||
|
mock_model.transcribe.return_value = (iter(mock_segments), mock_info)
|
||||||
|
|
||||||
|
# Track write_message calls
|
||||||
|
written_messages = []
|
||||||
|
|
||||||
|
def mock_write(msg):
|
||||||
|
written_messages.append(msg)
|
||||||
|
|
||||||
|
service = TranscribeService()
|
||||||
|
service._model = mock_model
|
||||||
|
service._current_model_name = "base"
|
||||||
|
service._current_device = "cpu"
|
||||||
|
service._current_compute_type = "int8"
|
||||||
|
|
||||||
|
with patch("voice_to_notes.services.transcribe.write_message", mock_write):
|
||||||
|
service.transcribe("req-1", "/fake/audio.wav")
|
||||||
|
|
||||||
|
# Filter for "transcribing" stage progress messages
|
||||||
|
transcribing_msgs = [
|
||||||
|
m for m in written_messages
|
||||||
|
if m.type == "progress" and m.payload.get("stage") == "transcribing"
|
||||||
|
]
|
||||||
|
|
||||||
|
# Should have one per segment (8) + the initial "Starting transcription..." message
|
||||||
|
# The initial "Starting transcription..." is also stage "transcribing" — so 8 + 1 = 9
|
||||||
|
assert len(transcribing_msgs) >= 8, (
|
||||||
|
f"Expected at least 8 transcribing progress messages (one per segment), got {len(transcribing_msgs)}"
|
||||||
|
)
|
||||||
|
|||||||
@@ -145,16 +145,14 @@ class TranscribeService:
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
# Send progress every few segments
|
write_message(
|
||||||
if segment_count % 5 == 0:
|
progress_message(
|
||||||
write_message(
|
request_id,
|
||||||
progress_message(
|
progress_pct,
|
||||||
request_id,
|
"transcribing",
|
||||||
progress_pct,
|
f"Transcribing segment {segment_count} ({progress_pct}% of audio)...",
|
||||||
"transcribing",
|
|
||||||
f"Processed {segment_count} segments...",
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
|
)
|
||||||
|
|
||||||
elapsed = time.time() - start_time
|
elapsed = time.time() - start_time
|
||||||
print(
|
print(
|
||||||
|
|||||||
Reference in New Issue
Block a user