Skip to content

Change at runtime with no SDK changes using <audio> for source #1

@horatio-sans-serif

Description

@horatio-sans-serif

Maybe this is useful for others. Tested with twilio-client 1.13.1.

const audio = document.createElement('audio');
audio.setAttribute('src', your_audio_url);
document.body.appendChild(audio);

const ctx = new AudioContext();
const src = new MediaElementAudioSourceNode(ctx, { mediaElement: audio });
const dst = new MediaStreamAudioDestinationNode(ctx);
src.connect(dst);
your_twilio_device.activeConnection().mediaStream.setInputTracksFromStream(dst.stream);

audio.addEventListener('ended', () => your_twilio_device.disconnectAll());
audio.play();

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions