From de8514228c6ee97015a888faaf5e5f55521b3ff1 Mon Sep 17 00:00:00 2001 From: Evan Feenstra Date: Wed, 2 Oct 2024 12:42:27 -0700 Subject: [PATCH] transcripts --- app/custom/VideoConferenceClientImpl.tsx | 31 ++++++++++++++++++- app/rooms/[roomName]/PageClientImpl.tsx | 39 ++++++++++++++++++++++-- lib/Transcript.tsx | 9 ++++++ styles/Transcript.module.css | 14 +++++++++ 4 files changed, 90 insertions(+), 3 deletions(-) create mode 100644 lib/Transcript.tsx create mode 100644 styles/Transcript.module.css diff --git a/app/custom/VideoConferenceClientImpl.tsx b/app/custom/VideoConferenceClientImpl.tsx index 02b779c..391ddb6 100644 --- a/app/custom/VideoConferenceClientImpl.tsx +++ b/app/custom/VideoConferenceClientImpl.tsx @@ -7,11 +7,13 @@ import { Room, RoomConnectOptions, RoomOptions, + RoomEvent, VideoPresets, + type TranscriptionSegment, type VideoCodec, } from 'livekit-client'; import { DebugMode } from '@/lib/Debug'; -import { useMemo } from 'react'; +import { useMemo, useEffect, useState } from 'react'; import { decodePassphrase } from '@/lib/client-utils'; import { SettingsMenu } from '@/lib/SettingsMenu'; @@ -57,6 +59,33 @@ export function VideoConferenceClientImpl(props: { }; }, []); + const [transcriptions, setTranscriptions] = useState<{ [id: string]: TranscriptionSegment }>({}); + useEffect(() => { + if (!room) { + return; + } + console.log('ROOM!!!'); + const updateTranscriptions = ( + segments: TranscriptionSegment[], + participant: any, + publication: any, + ) => { + console.log('received transcriptions', segments); + setTranscriptions((prev) => { + const newTranscriptions = { ...prev }; + for (const segment of segments) { + newTranscriptions[segment.id] = segment; + } + console.log('===>', newTranscriptions); + return newTranscriptions; + }); + }; + room.on(RoomEvent.TranscriptionReceived, updateTranscriptions); + return () => { + room.off(RoomEvent.TranscriptionReceived, updateTranscriptions); + }; + }, [room]); + return ( ({}); + const [latestText, setLatestText] = React.useState(''); + React.useEffect(() => { + if (!room) { + return; + } + const updateTranscriptions = ( + segments: TranscriptionSegment[], + participant: any, + publication: any, + ) => { + if (segments.length > 0) { + setLatestText(segments[0].text); + } + // setTranscriptions((prev) => { + // const newTranscriptions = { ...prev }; + // for (const segment of segments) { + // newTranscriptions[segment.id] = segment; + // } + // console.log('===>', newTranscriptions); + // return newTranscriptions; + // }); + }; + room.on(RoomEvent.TranscriptionReceived, updateTranscriptions); + return () => { + room.off(RoomEvent.TranscriptionReceived, updateTranscriptions); + }; + }, [room]); + const router = useRouter(); const handleOnLeave = React.useCallback(() => router.push('/'), [router]); @@ -172,8 +206,9 @@ function VideoConferenceComponent(props: { chatMessageFormatter={formatChatMessageLinks} SettingsComponent={SHOW_SETTINGS_MENU ? SettingsMenu : undefined} /> - + {/* */} + ); diff --git a/lib/Transcript.tsx b/lib/Transcript.tsx new file mode 100644 index 0000000..ed69ea4 --- /dev/null +++ b/lib/Transcript.tsx @@ -0,0 +1,9 @@ +import styles from '../styles/Transcript.module.css'; + +export default function Transcript(props: { latestText: string }) { + return ( +
+

{props.latestText}

+
+ ); +} diff --git a/styles/Transcript.module.css b/styles/Transcript.module.css new file mode 100644 index 0000000..86939f6 --- /dev/null +++ b/styles/Transcript.module.css @@ -0,0 +1,14 @@ + +.wrap { + position:absolute; + top: 32px; + width:100%; + left:0; + right:0; +} + +.text{ + color:white; + text-align:center; + margin:16px; +} \ No newline at end of file