fix: format text transcripts and show speaker markers

Chunked text output previously joined every word into one line and discarded
speaker labels. Add a shared plain-text formatter that wraps lines, breaks
paragraphs at speaker changes and pauses, and splits long turns while
preserving word order. Display provider speaker IDs with chunk scope where
needed, without implying that IDs identify the same person across requests.

Request structured output for short diarized recordings too, and warn when
speaker labels are missing or incomplete. Keep SRT formatting separate and
preserve existing line breaks for short requests without diarization.

Test Plan:
- python3 -B -m unittest -q: all 43 tests passed.
- bash -n transcribe and git diff --cached --check: passed.
- Reflowed the existing transcript locally and verified all 15,888 words
  were preserved; source audio and generated transcripts are not committed.
- A live excerpt check was blocked before upload by unavailable 1Password
  access; actual provider diarization remains unverified.
This commit is contained in:
ddidderr committed 2026-09-12 09:26:21 +02:00
1 parent 24b1030776
commit 38894c2549
7 files changed
+249 -19

No files matched your search

+38 -4
View File
@@ -53,7 +53,7 @@ class TranscribeTests(unittest.TestCase):
def test_long_text_uploads_bounded_mp3_and_stitches_once(self):
result = self.run_cli("--chunk-minutes", "1")
self.assertEqual(result.returncode, 0, result.stderr)
self.assertEqual(result.stdout, "Hello. boundary continues. Last.\n")
self.assertEqual(result.stdout, "Hello.\n\nboundary continues.\n\nLast.\n")
self.assertIn("chunk 2/2", result.stderr)
requests = self.requests()
self.assertEqual(len(requests), 2)
@@ -73,15 +73,49 @@ class TranscribeTests(unittest.TestCase):
self.assert_diarization(True)
self.assert_cleaned()
def test_short_text_retains_provider_formatting(self):
result = self.run_cli(duration=5)
def test_short_text_without_diarization_retains_provider_line_breaks(self):
result = self.run_cli("--no-diarization", duration=5)
self.assertEqual(result.returncode, 0, result.stderr)
self.assertEqual(result.stdout, "Provider's original formatting.\nNext line.\n")
self.assertEqual(len(self.requests()), 1)
self.assertIsNone(self.requests()[0]["response_format"])
self.assert_diarization(True)
self.assert_diarization(False)
self.assert_cleaned()
def test_short_text_requests_and_prints_speaker_labels(self):
result = self.run_cli(mode="speakers", duration=5)
self.assertEqual(result.returncode, 0, result.stderr)
self.assertEqual(result.stdout, "[Speaker 0]\nHello\n\n[Speaker 1]\nthere\n")
self.assertEqual(self.requests()[0]["response_format"], "verbose_json")
self.assertEqual(self.requests()[0]["timestamp_granularities"], ["segment", "word"])
self.assert_diarization(True)
self.assertEqual(result.stderr, "")
self.assert_cleaned()
def test_chunked_text_prints_speaker_ids_with_request_scope(self):
result = self.run_cli("--chunk-minutes", "1", mode="speakers")
self.assertEqual(result.returncode, 0, result.stderr)
self.assertEqual(result.stdout, (
"[Chunk 1, Speaker 0]\nHello.\n\n"
"[Chunk 1, Speaker 0]\nboundary\n\n"
"[Chunk 2, Speaker 1]\ncontinues.\n\n"
"[Chunk 2, Speaker 1]\nLast.\n"
))
self.assertNotIn("Warning", result.stderr)
self.assert_cleaned()
def test_missing_speaker_labels_warn_instead_of_implying_detection_worked(self):
for output in ((), ("--srt",)):
with self.subTest(output=output):
result = self.run_cli(*output, duration=5)
self.assertEqual(result.returncode, 0, result.stderr)
self.assertIn("returned no speaker labels", result.stderr)
self.assertNotIn("[Speaker", result.stdout)
result = self.run_cli(mode="partial-speakers", duration=5)
self.assertEqual(result.returncode, 0, result.stderr)
self.assertIn("some words without speaker labels", result.stderr)
self.assertEqual(result.stdout, "[Speaker 0]\nHello\n\n[Speaker unknown]\nthere\n")
def test_short_srt_still_requests_word_timestamps(self):
result = self.run_cli("--srt", duration=5)
self.assertEqual(result.returncode, 0, result.stderr)