From d7917c3698efaab029f8e7a704e8e73cd3340e7f Mon Sep 17 00:00:00 2001 From: Shubhrakanti Ganguly Date: Wed, 23 Jul 2025 15:12:56 -0700 Subject: [PATCH 1/3] init --- agents/src/voice/agent_session.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/agents/src/voice/agent_session.ts b/agents/src/voice/agent_session.ts index 2f15cbc2..1135f458 100644 --- a/agents/src/voice/agent_session.ts +++ b/agents/src/voice/agent_session.ts @@ -327,7 +327,7 @@ export class AgentSession< } // -- User changed input/output streams/sinks -- - private onAudioInputChanged(): void { + private onAudioInputChanged = (): void => { if (!this.started) { return; } @@ -335,9 +335,9 @@ export class AgentSession< if (this.activity && this._input.audio) { this.activity.attachAudioInput(this._input.audio.stream); } - } + }; - private onAudioOutputChanged(): void {} + private onAudioOutputChanged = (): void => {}; - private onTextOutputChanged(): void {} + private onTextOutputChanged = (): void => {}; } From a05f87b4a2e6d51eb02b8bd45c06e60543d69321 Mon Sep 17 00:00:00 2001 From: Shubhrakanti Ganguly Date: Wed, 23 Jul 2025 15:14:23 -0700 Subject: [PATCH 2/3] update audio input update --- agents/src/voice/agent_activity.ts | 9 +++------ agents/src/voice/agent_session.ts | 1 + 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/agents/src/voice/agent_activity.ts b/agents/src/voice/agent_activity.ts index 88cdc8b3..e23bab2b 100644 --- a/agents/src/voice/agent_activity.ts +++ b/agents/src/voice/agent_activity.ts @@ -334,11 +334,6 @@ export class AgentActivity implements RecognitionHooks { } attachAudioInput(audioStream: ReadableStream): void { - if (this.audioStream.isSourceSet) { - this.logger.debug('detaching existing audio input in agent activity'); - this.audioStream.detachSource(); - } - /** * We need to add a deferred ReadableStream layer on top of the audioStream from the agent session. * The tee() operation should be applied to the deferred stream, not the original audioStream. @@ -358,7 +353,9 @@ export class AgentActivity implements RecognitionHooks { } detachAudioInput(): void { - this.audioStream.detachSource(); + if (this.audioStream.isSourceSet) { + this.audioStream.detachSource(); + } } commitUserTurn() { diff --git a/agents/src/voice/agent_session.ts b/agents/src/voice/agent_session.ts index 1135f458..8662ba87 100644 --- a/agents/src/voice/agent_session.ts +++ b/agents/src/voice/agent_session.ts @@ -333,6 +333,7 @@ export class AgentSession< } if (this.activity && this._input.audio) { + this.activity.detachAudioInput(); this.activity.attachAudioInput(this._input.audio.stream); } }; From ea0947c127462ca647909020f9c771a481ec2c72 Mon Sep 17 00:00:00 2001 From: Shubhrakanti Ganguly Date: Thu, 24 Jul 2025 11:48:32 +0100 Subject: [PATCH 3/3] update --- agents/src/voice/agent_activity.ts | 3 ++- agents/src/voice/agent_session.ts | 5 ++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/agents/src/voice/agent_activity.ts b/agents/src/voice/agent_activity.ts index e23bab2b..4fddb9b7 100644 --- a/agents/src/voice/agent_activity.ts +++ b/agents/src/voice/agent_activity.ts @@ -333,7 +333,8 @@ export class AgentActivity implements RecognitionHooks { } } - attachAudioInput(audioStream: ReadableStream): void { + updateAudioInput(audioStream: ReadableStream): void { + this.detachAudioInput(); /** * We need to add a deferred ReadableStream layer on top of the audioStream from the agent session. * The tee() operation should be applied to the deferred stream, not the original audioStream. diff --git a/agents/src/voice/agent_session.ts b/agents/src/voice/agent_session.ts index 8662ba87..fc322aec 100644 --- a/agents/src/voice/agent_session.ts +++ b/agents/src/voice/agent_session.ts @@ -272,7 +272,7 @@ export class AgentSession< await this.activity.start(); if (this._input.audio) { - this.activity.attachAudioInput(this._input.audio.stream); + this.activity.updateAudioInput(this._input.audio.stream); } } @@ -333,8 +333,7 @@ export class AgentSession< } if (this.activity && this._input.audio) { - this.activity.detachAudioInput(); - this.activity.attachAudioInput(this._input.audio.stream); + this.activity.updateAudioInput(this._input.audio.stream); } };