fix: avoid duplicate agent speech end (#6938)
This commit is contained in:
@@ -2265,8 +2265,8 @@ class AgentActivity(RecognitionHooks):
|
||||
self._interrupt_by_audio_activity(
|
||||
ignore_user_transcript_until=ev.overlap_started_at or ev.detected_at
|
||||
)
|
||||
# flush held transcripts again if possible
|
||||
if self._audio_recognition:
|
||||
# flush held transcripts if the pause path did not already end agent speech
|
||||
if self._audio_recognition and self._paused_speech is None:
|
||||
self._audio_recognition._on_end_of_agent_speech(
|
||||
ignore_user_transcript_until=ev.overlap_started_at or ev.detected_at
|
||||
)
|
||||
|
||||
@@ -316,6 +316,30 @@ async def test_interrupting_paused_speech_does_not_end_agent_twice(
|
||||
activity._audio_recognition._on_end_of_agent_speech.assert_not_called()
|
||||
|
||||
|
||||
async def test_interruption_event_does_not_end_agent_again_after_pausing(
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
) -> None:
|
||||
monkeypatch.setenv("LIVEKIT_API_KEY", "k")
|
||||
monkeypatch.setenv("LIVEKIT_API_SECRET", "s")
|
||||
|
||||
session = _session()
|
||||
session.options.interruption["resume_false_interruption"] = True
|
||||
session.options.interruption["false_interruption_timeout"] = FALSE_INTERRUPTION_TIMEOUT
|
||||
activity, handle = _paused_activity(session)
|
||||
handle._generations = []
|
||||
activity._paused_speech = None
|
||||
activity._audio_recognition = MagicMock()
|
||||
event = MagicMock(overlap_started_at=1.0, detected_at=2.0)
|
||||
|
||||
activity.on_interruption(event)
|
||||
assert activity._paused_speech is not None
|
||||
await session.aclose()
|
||||
|
||||
activity._audio_recognition._on_end_of_agent_speech.assert_called_once_with(
|
||||
ignore_user_transcript_until=1.0
|
||||
)
|
||||
|
||||
|
||||
async def test_handing_over_a_paused_speech_does_not_end_the_agent_turn(
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
) -> None:
|
||||
|
||||
Reference in New Issue
Block a user