Skip to content

Small fixes in Agent I/O #574

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: dev-1.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions agents/src/voice/agent_activity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -333,12 +333,8 @@ export class AgentActivity implements RecognitionHooks {
}
}

attachAudioInput(audioStream: ReadableStream<AudioFrame>): void {
if (this.audioStream.isSourceSet) {
this.logger.debug('detaching existing audio input in agent activity');
this.audioStream.detachSource();
}

updateAudioInput(audioStream: ReadableStream<AudioFrame>): void {
this.detachAudioInput();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you tested if it work?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a check if (this.audioStream.isSourceSet)?

/**
* 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.
Expand All @@ -358,7 +354,9 @@ export class AgentActivity implements RecognitionHooks {
}

detachAudioInput(): void {
this.audioStream.detachSource();
if (this.audioStream.isSourceSet) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be a check here right?

this.audioStream.detachSource();
}
}

commitUserTurn() {
Expand Down
12 changes: 6 additions & 6 deletions agents/src/voice/agent_session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -327,17 +327,17 @@ export class AgentSession<
}

// -- User changed input/output streams/sinks --
private onAudioInputChanged(): void {
private onAudioInputChanged = (): void => {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

event listeners should be arrow functions

if (!this.started) {
return;
}

if (this.activity && this._input.audio) {
this.activity.attachAudioInput(this._input.audio.stream);
this.activity.updateAudioInput(this._input.audio.stream);
}
}
};

private onAudioOutputChanged(): void {}
private onAudioOutputChanged = (): void => {};

private onTextOutputChanged(): void {}
private onTextOutputChanged = (): void => {};
}