-
Notifications
You must be signed in to change notification settings - Fork 151
Expand file tree
/
Copy pathuseTranscriptions.ts
More file actions
44 lines (40 loc) · 1.28 KB
/
useTranscriptions.ts
File metadata and controls
44 lines (40 loc) · 1.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import * as React from 'react';
import { useTextStream } from './useTextStream';
import { DataTopic } from '@livekit/components-core';
/**
* @beta
*/
export interface UseTranscriptionsOptions {
participantIdentities?: string[];
trackSids?: string[];
}
/**
* @beta
* useTranscriptions is a hook that returns the transcriptions for the given participant identities and track sids,
* if no options are provided, it will return all transcriptions
* @example
* ```tsx
* const transcriptions = useTranscriptions();
* return <div>{transcriptions.map((transcription) => transcription.text)}</div>;
* ```
*/
export function useTranscriptions(opts?: UseTranscriptionsOptions) {
const { participantIdentities, trackSids } = opts ?? {};
const { textStreams } = useTextStream(DataTopic.TRANSCRIPTION);
const filteredMessages = React.useMemo(
() =>
textStreams
.filter((stream) =>
participantIdentities
? participantIdentities.includes(stream.participantInfo.identity)
: true,
)
.filter((stream) =>
trackSids
? trackSids.includes(stream.streamInfo.attributes?.['lk.transcribed_track_id'] ?? '')
: true,
),
[textStreams, participantIdentities, trackSids],
);
return filteredMessages;
}