Skip to content
Merged
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
1 change: 1 addition & 0 deletions src/AnamClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ export default class AnamClient {
inputAudio: {
inputAudioState: this.inputAudioState,
userProvidedMediaStream: userProvidedAudioStream,
audioDeviceId: this.clientOptions?.audioDeviceId,
},
},
this.publicEventEmitter,
Expand Down
17 changes: 14 additions & 3 deletions src/modules/StreamingClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export class StreamingClient {
private audioElement: HTMLAudioElement | null = null;
private audioStream: MediaStream | null = null;
private inputAudioState: InputAudioState = { isMuted: false };
private audioDeviceId: string | undefined;

constructor(
sessionId: string,
Expand Down Expand Up @@ -75,6 +76,7 @@ export class StreamingClient {
options.engine.baseUrl,
sessionId,
);
this.audioDeviceId = options.inputAudio.audioDeviceId;
}

private onInputAudioStateChange(
Expand Down Expand Up @@ -420,10 +422,19 @@ export class StreamingClient {
);
}
} else {
const audioConstraints: MediaTrackConstraints = {
echoCancellation: true,
};

// If an audio device ID is provided in the options, use it
if (this.audioDeviceId) {
audioConstraints.deviceId = {
exact: this.audioDeviceId,
};
}

this.inputAudioStream = await navigator.mediaDevices.getUserMedia({
audio: {
echoCancellation: true,
},
audio: audioConstraints,
});
}

Expand Down
1 change: 1 addition & 0 deletions src/types/AnamPublicClientOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ import { VoiceDetectionOptions } from './VoiceDetectionOptions';
export interface AnamPublicClientOptions {
api?: CoreApiRestClientOptions;
voiceDetection?: VoiceDetectionOptions;
audioDeviceId?: string;
}
1 change: 1 addition & 0 deletions src/types/streaming/InputAudioOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ import { InputAudioState } from '../InputAudioState';
export interface InputAudioOptions {
inputAudioState: InputAudioState;
userProvidedMediaStream?: MediaStream;
audioDeviceId?: string;
}