Updated openvidu-live-captions

This commit is contained in:
pabloFuente 2025-06-27 17:43:53 +02:00
parent af880945dc
commit 12b2c3720a

View File

@ -57,28 +57,30 @@ async function joinRoom() {
} }
); );
room.registerTextStreamHandler("lk.transcription", async (reader, participantInfo) => { room.registerTextStreamHandler("lk.transcription", async (reader, participantInfo) => {
const message = await reader.readAll(); const message = await reader.readAll();
const isFinal = reader.info.attributes["lk.transcription_final"] === "true"; const isFinal = reader.info.attributes["lk.transcription_final"] === "true";
const trackId = reader.info.attributes["lk.transcribed_track_id"];
if (isFinal) { if (isFinal) {
const audioTrackId = reader.info.attributes["lk.transcribed_track_id"]; // Due to a bug in LiveKit Server the participantInfo object may be empty.
// You can still get the participant owning the audio track like below:
// Due to a bug in LiveKit Server the participantInfo object may be empty. let participant;
// You can still get the participant owning the audio track like below: if (localParticipant.audioTrackPublications.has(trackId)) {
const participant = [room.localParticipant] participant = room.localParticipant;
.concat(Array.from(room.remoteParticipants.values())) } else {
.find((p) => p.audioTrackPublications.has(audioTrackId)); participant = room.remoteParticipants.values().find(p => p.audioTrackPublications.has(trackId));
const captionsTextarea = document.getElementById("captions");
const timestamp = new Date().toLocaleTimeString();
const participantIdentity =
participant == room.localParticipant ? "You" : participant.identity;
captionsTextarea.value += `[${timestamp}] ${participantIdentity}: ${message}\n`;
captionsTextarea.scrollTop = captionsTextarea.scrollHeight;
} }
const captionsTextarea = document.getElementById("captions");
const timestamp = new Date().toLocaleTimeString();
const participantIdentity =
participant == room.localParticipant ? "You" : participant.identity;
captionsTextarea.value += `[${timestamp}] ${participantIdentity}: ${message}\n`;
captionsTextarea.scrollTop = captionsTextarea.scrollHeight;
} }
); }
);
try { try {
// Get the room name and participant name from the form // Get the room name and participant name from the form