Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,16 @@ def test_draft_is_revisable_and_final_comes_from_decoder(self):
self.assertEqual(snapshots.update("你好", "你好")["draft"], "")
final = snapshots.update("你好", "你好!", terminal=True)
self.assertEqual((final["finalized"], final["draft"]), ("你好!", ""))
with self.assertRaises(ValueError):
snapshots.update("cannot match", "different")
# A rewritten decode must re-commit only the agreed prefix instead of
# failing: audio is already captured and the terminal text wins.
recovered = snapshots.update("cannot match", "different")
self.assertEqual(recovered["finalized"], "")
self.assertEqual(recovered["finalized"] + recovered["draft"], "different")
partial = snapshots.update("我们去了Co", "我们去了科蒂纳。")
self.assertEqual(
(partial["finalized"], partial["draft"]), ("我们去了", "科蒂纳。")
)
self.assertNotEqual(snapshots.sequence, 0)

def run_fake(self, finish=True, gpu_available=True):
FakeSession.calls = []
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,17 @@ def update(self, finalized: str, full: str, terminal: bool = False) -> dict:
if terminal:
finalized = full
if not full.startswith(finalized):
raise ValueError("decoder snapshot does not contain its finalized prefix")
# A decode may rewrite text that an earlier snapshot reported as
# stable (script or normalisation flips). The protocol carries whole
# previews, and the terminal snapshot is authoritative, so keep the
# authoritative text and re-commit only the prefix both agree on
# instead of failing the whole transcription.
agreed = 0
for previous, current in zip(finalized, full):
if previous != current:
break
agreed += 1
finalized = finalized[:agreed]
self.finalized, self.draft = finalized, full[len(finalized) :]
self.sequence += 1
return {
Expand Down
Loading