twilio / twilio-voice.js

Twilio's JavaScript Voice SDK
Other
56 stars 54 forks source link

[TECHNICAL QUESTION] Control volume of Incoming Call #295

Closed gabrielSoudry closed 1 month ago

gabrielSoudry commented 1 month ago

Description: Hi, I'm Bob. I'm working on a Twilio-based application where I receive calls from Alice, and I want to be able to control the volume of Alice's audio during the call. Specifically, I'd like to add a slider in my application that allows me to increase or decrease the volume of the incoming audio stream.

What I've Tried:

call.on('audio', (audio: HTMLAudioElement) => {
  setCurrentAudio(audio);
  audio.volume = 0.5; // But this has no effect on the volume of the incoming call
});

I also tried retrieving the remote stream and using an AudioContext to control the volume via a GainNode. However, this approach seems to create a duplicate media stream rather than controlling the volume of the existing one:

const stream = activeCall.getRemoteStream();
    stream.getAudioTracks().forEach((track) => console.log(track));
    const source = audioCtx.createMediaStreamSource(stream);
    const gainNode = audioCtx.createGain();
    gainNode.gain.value = 0.5;

What I Want: I want to implement a slider control in my application that allows me to dynamically adjust the volume of the incoming audio during a call with Alice. However, I'm unable to figure out how to achieve this, as modifying the audio element's volume property doesn't seem to work.

Any guidance on how to implement this volume control would be greatly appreciated!

charliesantos commented 1 month ago

Thanks for reaching out @gabrielSoudry . Unfortunately, we currently do not expose this functionality. Your current approach to use AudioContext and GainNode is the best option for now.

gabrielSoudry commented 1 month ago

Thank you !