@@ -45,7 +45,11 @@ export default class AnamClient {
4545 options ,
4646 ) ;
4747 if ( configError ) {
48- throw new Error ( configError ) ;
48+ throw new ClientError (
49+ configError ,
50+ ErrorCode . CLIENT_ERROR_CODE_CONFIGURATION_ERROR ,
51+ 400 ,
52+ ) ;
4953 }
5054
5155 this . personaConfig = personaConfig ;
@@ -114,6 +118,9 @@ export default class AnamClient {
114118
115119 // Validate voice detection configuration
116120 if ( options ?. voiceDetection ) {
121+ if ( options . disableInputAudio ) {
122+ return 'Voice detection is disabled because input audio is disabled. Please set disableInputAudio to false to enable voice detection.' ;
123+ }
117124 // End of speech sensitivity must be a number between 0 and 1
118125 if ( options . voiceDetection . endOfSpeechSensitivity !== undefined ) {
119126 if ( typeof options . voiceDetection . endOfSpeechSensitivity !== 'number' ) {
@@ -183,8 +190,11 @@ export default class AnamClient {
183190 iceServers,
184191 inputAudio : {
185192 inputAudioState : this . inputAudioState ,
186- userProvidedMediaStream : userProvidedAudioStream ,
193+ userProvidedMediaStream : this . clientOptions ?. disableInputAudio
194+ ? undefined
195+ : userProvidedAudioStream ,
187196 audioDeviceId : this . clientOptions ?. audioDeviceId ,
197+ disableInputAudio : this . clientOptions ?. disableInputAudio ,
188198 } ,
189199 } ,
190200 this . publicEventEmitter ,
@@ -203,9 +213,9 @@ export default class AnamClient {
203213 return sessionId ;
204214 }
205215
206- private async startSessionIfNeeded ( userProvidedMediaStream ?: MediaStream ) {
216+ private async startSessionIfNeeded ( userProvidedAudioStream ?: MediaStream ) {
207217 if ( ! this . sessionId || ! this . streamingClient ) {
208- await this . startSession ( userProvidedMediaStream ) ;
218+ await this . startSession ( userProvidedAudioStream ) ;
209219
210220 if ( ! this . sessionId || ! this . streamingClient ) {
211221 throw new ClientError (
@@ -223,6 +233,11 @@ export default class AnamClient {
223233 public async stream (
224234 userProvidedAudioStream ?: MediaStream ,
225235 ) : Promise < MediaStream [ ] > {
236+ if ( this . clientOptions ?. disableInputAudio && userProvidedAudioStream ) {
237+ console . warn (
238+ 'AnamClient:Input audio is disabled. User provided audio stream will be ignored.' ,
239+ ) ;
240+ }
226241 await this . startSessionIfNeeded ( userProvidedAudioStream ) ;
227242 if ( this . _isStreaming ) {
228243 throw new Error ( 'Already streaming' ) ;
@@ -261,10 +276,15 @@ export default class AnamClient {
261276 public async streamToVideoAndAudioElements (
262277 videoElementId : string ,
263278 audioElementId : string ,
264- userProvidedMediaStream ?: MediaStream ,
279+ userProvidedAudioStream ?: MediaStream ,
265280 ) : Promise < void > {
281+ if ( this . clientOptions ?. disableInputAudio && userProvidedAudioStream ) {
282+ console . warn (
283+ 'AnamClient:Input audio is disabled. User provided audio stream will be ignored.' ,
284+ ) ;
285+ }
266286 try {
267- await this . startSessionIfNeeded ( userProvidedMediaStream ) ;
287+ await this . startSessionIfNeeded ( userProvidedAudioStream ) ;
268288 } catch ( error ) {
269289 if ( error instanceof ClientError ) {
270290 throw error ;
@@ -340,14 +360,24 @@ export default class AnamClient {
340360 }
341361
342362 public getInputAudioState ( ) : InputAudioState {
363+ if ( this . clientOptions ?. disableInputAudio ) {
364+ console . warn (
365+ 'AnamClient: Audio state will not be used because input audio is disabled.' ,
366+ ) ;
367+ }
343368 // if streaming client is available, make sure our state is up to date
344369 if ( this . streamingClient ) {
345370 this . inputAudioState = this . streamingClient . getInputAudioState ( ) ;
346371 }
347372 return this . inputAudioState ;
348373 }
349374 public muteInputAudio ( ) : InputAudioState {
350- if ( this . streamingClient ) {
375+ if ( this . clientOptions ?. disableInputAudio ) {
376+ console . warn (
377+ 'AnamClient: Input audio is disabled. Muting input audio will have no effect.' ,
378+ ) ;
379+ }
380+ if ( this . streamingClient && ! this . clientOptions ?. disableInputAudio ) {
351381 this . inputAudioState = this . streamingClient . muteInputAudio ( ) ;
352382 } else {
353383 this . inputAudioState = {
@@ -359,7 +389,12 @@ export default class AnamClient {
359389 }
360390
361391 public unmuteInputAudio ( ) : InputAudioState {
362- if ( this . streamingClient ) {
392+ if ( this . clientOptions ?. disableInputAudio ) {
393+ console . warn (
394+ 'AnamClient: Input audio is disabled. Unmuting input audio will have no effect.' ,
395+ ) ;
396+ }
397+ if ( this . streamingClient && ! this . clientOptions ?. disableInputAudio ) {
363398 this . inputAudioState = this . streamingClient . unmuteInputAudio ( ) ;
364399 } else {
365400 this . inputAudioState = {
0 commit comments