Skip to content

Commit

Permalink
Reset check_human_present_count when human is actually present (#696)
Browse files Browse the repository at this point in the history
  • Loading branch information
vocode-petern authored Aug 30, 2024
1 parent b0ca4d8 commit 84c2971
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions vocode/streaming/streaming_conversation.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,7 @@ async def process(self, transcription: Transcription):
if self.conversation.current_transcription_is_interrupt:
logger.debug("sent interrupt")
logger.debug("Human started speaking")
self.conversation.is_human_still_there = True

transcription.is_interrupt = self.conversation.current_transcription_is_interrupt
self.conversation.is_human_speaking = not transcription.is_final
Expand Down Expand Up @@ -667,6 +668,7 @@ def __init__(

self.check_for_idle_task: Optional[asyncio.Task] = None
self.check_for_idle_paused = False
self.is_human_still_there = True

self.current_transcription_is_interrupt: bool = False

Expand Down Expand Up @@ -762,12 +764,16 @@ async def check_for_idle(self):
check_human_present_count = 0
check_human_present_threshold = self.agent.get_agent_config().num_check_human_present_times
while self.is_active():
if check_human_present_count > 0 and self.is_human_still_there == True:
# Reset the counter if the human is still there
check_human_present_count = 0
if (
not self.check_for_idle_paused
) and time.time() - self.last_action_timestamp > self.idle_time_threshold:
if check_human_present_count >= check_human_present_threshold:
# Stop the phone call after some retries to prevent infinitely long call where human is just silent.
await self.action_on_idle()
self.is_human_still_there = False
await self.send_single_message(
message=BaseMessage(text=random.choice(CHECK_HUMAN_PRESENT_MESSAGE_CHOICES)),
)
Expand Down

0 comments on commit 84c2971

Please sign in to comment.