Share browser audio

LiveKit clients can share audio playing from a browser tab

caution:

Sharing audio is only possible in certain browsers. Check browser support on MDN's compatibility table.

Assuming your client has already connected to a LiveKit Room:

const tracks = await localParticipant.createScreenTracks({
audio: true,
});
tracks.forEach((track) => {
localParticipant.publishTrack(track);
});

Testing

Publisher

When sharing audio, make sure you select a Browser Tab (not a Window) and ☑️ Share tab audio, otherwise no audio track will be generated when calling createScreenTracks:

Popup window for choosing to share entire screen, a specific window, or a Chrome tab, with options to share audio and action buttons.

Subscriber

On the receiving side, you can use RoomAudioRenderer to play all audio tracks of the room automatically, AudioTrack or your own custom <audio> tag to add the track to the page. If you don't hear any sound, check you're receiving the track from the server:

room.getParticipantByIdentity('<participant_id>').getTrackPublication('screen_share_audio')