Skip to content

Commit d9de589

Browse files
Add Penalty when Smart Turn hasn't been run (#86)
* Add No Signal Penalty for Smart Turn * Update Penalty to Extend TTL
1 parent 301bcf4 commit d9de589

2 files changed

Lines changed: 10 additions & 0 deletions

File tree

sdk/voice/speechmatics/voice/_client.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,7 @@ def __init__(
318318
)
319319

320320
# Uses ForceEndOfUtterance message
321+
# Todo - fix this logic as use FEOU isn't the same as just not using fixed.
321322
self._uses_forced_eou: bool = not self._uses_fixed_eou
322323
self._forced_eou_active: bool = False
323324
self._last_forced_eou_latency: float = 0.0
@@ -1421,6 +1422,7 @@ async def _emit_end_of_turn(self) -> None:
14211422
# Flag as turn active
14221423
self._turn_active = False
14231424

1425+
14241426
# Metadata (for LAST view)
14251427
metadata = MessageTimeMetadata(start_time=self._turn_start_time, end_time=self._previous_view.end_time)
14261428

@@ -1526,6 +1528,10 @@ async def _calculate_finalize_delay(
15261528
# Smart Turn enabled
15271529
if self._smart_turn_detector:
15281530
annotation.add(AnnotationFlags.SMART_TURN_ACTIVE)
1531+
# If Smart Turn hasn't returned a result yet but is enabled, add NO_SIGNAL annotation.
1532+
# This covers the case where the TTL fires before VAD triggers Smart Turn inference.
1533+
if not annotation.has(AnnotationFlags.SMART_TURN_TRUE) and not annotation.has(AnnotationFlags.SMART_TURN_FALSE):
1534+
annotation.add(AnnotationFlags.SMART_TURN_NO_SIGNAL)
15291535
else:
15301536
annotation.add(AnnotationFlags.SMART_TURN_INACTIVE)
15311537

sdk/voice/speechmatics/voice/_models.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,7 @@ class AnnotationFlags(str, Enum):
261261
SMART_TURN_INACTIVE = "smart_turn_inactive"
262262
SMART_TURN_TRUE = "smart_turn_true"
263263
SMART_TURN_FALSE = "smart_turn_false"
264+
SMART_TURN_NO_SIGNAL = "smart_turn_no_signal"
264265

265266

266267
# ==============================================================================
@@ -445,6 +446,9 @@ class EndOfTurnConfig(BaseModel):
445446
EndOfTurnPenaltyItem(
446447
penalty=2.0, annotation=[AnnotationFlags.SMART_TURN_FALSE, AnnotationFlags.SMART_TURN_ACTIVE]
447448
),
449+
EndOfTurnPenaltyItem(
450+
penalty=1.5, annotation=[AnnotationFlags.SMART_TURN_NO_SIGNAL, AnnotationFlags.SMART_TURN_ACTIVE]
451+
),
448452
#
449453
# VAD - only applied when smart turn is not in use and on the speaker stopping
450454
EndOfTurnPenaltyItem(

0 commit comments

Comments
 (0)