WebSDK uses buildAudioPlayer by default to create Audio track through HTML element

I want to override the logic in the SDK when the call receives a 'track-started' event to be able to output the assistant's audio through my own source within a 3D scene using Three.js. I have been able to capture this audio source within my own component but I cannot remove the default behaviour of the SDK which creates an Audio HTML Element when an audio media stream track is received during the connection. I want to negate or remove this and need some way of overriding the initial event if possible - or perhaps a way of destroying the created Audio HTML Element whenever it is created if no other solution is present.

This is the part of the SDK which performs the behaviour I described:

this.call.on('track-started', async (e) => {
if (!e or !e.participant) {
return;
}
if (e.participant?.local) {
return;
}
if (e.participant?.user_name !== 'Vapi Speaker') {
return;
}
if (e.track.kind === 'video') {
this.emit('video', e.track);
}
if (e.track.kind === 'audio') {
await buildAudioPlayer(e.track, e.participant.session_id);
}
this.call?.sendAppMessage('playable');
});

This is how I am able to add my own functionality on top of that:

const call = this.vapi?.getDailyCallObject();

call?.on('track-started', (e: any) => {
if (!e or !e.participant) return;
if (e.participant.local) return;
if (e.participant.user_name !== 'Vapi Speaker') return;

if (e.track.kind === 'audio') {
this.setSpatialAudio(e.track);
}
});
Was this page helpful?