Skip to content

Commit 33e693f

Browse files
committed
refactor: enhance end of turn penalty logic
Refactor the EndOfTurnPenaltyItem logic to improve clarity and functionality. Group related penalty items with descriptive comments for better maintainability. Adjust penalties for situations with Smart Turn and VAD to improve detection accuracy, including new conditions for SMART_TURN_FALSE and ACTIVE combinations. This change is necessary to fine-tune the configuration for complex speech patterns and ensure better end-of-turn detection in the transcription process.
1 parent 5a5245e commit 33e693f

1 file changed

Lines changed: 24 additions & 5 deletions

File tree

sdk/voice/speechmatics/voice/_models.py

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -417,24 +417,43 @@ class EndOfTurnConfig(BaseModel):
417417
min_end_of_turn_delay: float = 0.01
418418
penalties: list[EndOfTurnPenaltyItem] = Field(
419419
default_factory=lambda: [
420-
# Increase delay
420+
#
421+
# Speaker rate increases expected TTL
421422
EndOfTurnPenaltyItem(penalty=3.0, annotation=[AnnotationFlags.VERY_SLOW_SPEAKER]),
422423
EndOfTurnPenaltyItem(penalty=2.0, annotation=[AnnotationFlags.SLOW_SPEAKER]),
424+
#
425+
# High / low rate of disfluencies
423426
EndOfTurnPenaltyItem(penalty=2.5, annotation=[AnnotationFlags.ENDS_WITH_DISFLUENCY]),
424427
EndOfTurnPenaltyItem(penalty=1.1, annotation=[AnnotationFlags.HAS_DISFLUENCY]),
428+
#
429+
# We do NOT have an end of sentence character
425430
EndOfTurnPenaltyItem(
426431
penalty=2.0,
427432
annotation=[AnnotationFlags.ENDS_WITH_EOS],
428433
is_not=True,
429434
),
430-
# Decrease delay
435+
#
436+
# We have finals and end of sentence
431437
EndOfTurnPenaltyItem(
432438
penalty=0.5, annotation=[AnnotationFlags.ENDS_WITH_FINAL, AnnotationFlags.ENDS_WITH_EOS]
433439
),
434-
# Smart Turn + VAD
435-
EndOfTurnPenaltyItem(penalty=0.2, annotation=[AnnotationFlags.SMART_TURN_TRUE]),
440+
#
441+
# Smart Turn - when false, wait longer to prevent premature end of turn
436442
EndOfTurnPenaltyItem(
437-
penalty=0.2, annotation=[AnnotationFlags.VAD_STOPPED, AnnotationFlags.SMART_TURN_INACTIVE]
443+
penalty=0.2, annotation=[AnnotationFlags.SMART_TURN_TRUE, AnnotationFlags.SMART_TURN_ACTIVE]
444+
),
445+
EndOfTurnPenaltyItem(
446+
penalty=2.0, annotation=[AnnotationFlags.SMART_TURN_FALSE, AnnotationFlags.SMART_TURN_ACTIVE]
447+
),
448+
#
449+
# VAD - only applied when smart turn is not in use and on the speaker stopping
450+
EndOfTurnPenaltyItem(
451+
penalty=0.2,
452+
annotation=[
453+
AnnotationFlags.VAD_STOPPED,
454+
AnnotationFlags.VAD_ACTIVE,
455+
AnnotationFlags.SMART_TURN_INACTIVE,
456+
],
438457
),
439458
]
440459
)

0 commit comments

Comments
 (0)