Skip to content

Commit d2b518c

Browse files
authored
Add callback option to trackTranscription hook (#939)
1 parent 0614b11 commit d2b518c

File tree

3 files changed

+14
-3
lines changed

3 files changed

+14
-3
lines changed

.changeset/sixty-singers-thank.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@livekit/components-react": patch
3+
---
4+
5+
Add callback option to trackTranscription hook

packages/react/etc/components-react.api.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -676,6 +676,7 @@ export interface TrackToggleProps<T extends ToggleSource> extends Omit<React_2.B
676676
// @alpha (undocumented)
677677
export interface TrackTranscriptionOptions {
678678
bufferSize?: number;
679+
onTranscription?: (newSegments: TranscriptionSegment[]) => void;
679680
}
680681

681682
// Warning: (ae-internal-missing-underscore) The name "UnfocusToggleIcon" should be prefixed with an underscore because the declaration is marked as @internal
@@ -880,7 +881,7 @@ export function useMediaDeviceSelect({ kind, room, track, requestPermissions, on
880881
devices: MediaDeviceInfo[];
881882
className: string;
882883
activeDeviceId: string;
883-
setActiveMediaDevice: (id: string, options?: SetMediaDeviceOptions | undefined) => Promise<void>;
884+
setActiveMediaDevice: (id: string, options?: SetMediaDeviceOptions) => Promise<void>;
884885
};
885886

886887
// @public (undocumented)
@@ -1151,7 +1152,7 @@ export type UseTracksOptions = {
11511152

11521153
// @public
11531154
export function useTrackToggle<T extends ToggleSource>({ source, onChange, initialState, captureOptions, publishOptions, onDeviceError, ...rest }: UseTrackToggleProps<T>): {
1154-
toggle: (forceState?: boolean | undefined, captureOptions?: CaptureOptionsBySource<T> | undefined) => Promise<void>;
1155+
toggle: (forceState?: boolean, captureOptions?: CaptureOptionsBySource<T> | undefined) => Promise<void>;
11551156
enabled: boolean;
11561157
pending: boolean;
11571158
track: LocalTrackPublication | undefined;
@@ -1223,7 +1224,7 @@ export type WidgetState = {
12231224
// src/context/layout-context.ts:11:3 - (ae-forgotten-export) The symbol "WidgetContextType" needs to be exported by the entry point index.d.ts
12241225
// src/hooks/useGridLayout.ts:27:6 - (ae-forgotten-export) The symbol "GridLayoutInfo" needs to be exported by the entry point index.d.ts
12251226
// src/hooks/useMediaDeviceSelect.ts:47:29 - (ae-forgotten-export) The symbol "SetMediaDeviceOptions" needs to be exported by the entry point index.d.ts
1226-
// src/hooks/useTrackTranscription.ts:39:38 - (ae-forgotten-export) The symbol "ReceivedTranscriptionSegment" needs to be exported by the entry point index.d.ts
1227+
// src/hooks/useTrackTranscription.ts:43:38 - (ae-forgotten-export) The symbol "ReceivedTranscriptionSegment" needs to be exported by the entry point index.d.ts
12271228

12281229
// (No @packageDocumentation comment for this package)
12291230

packages/react/src/hooks/useTrackTranscription.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ export interface TrackTranscriptionOptions {
2121
* @defaultValue 100
2222
*/
2323
bufferSize?: number;
24+
/**
25+
* optional callback for retrieving newly incoming transcriptions only
26+
*/
27+
onTranscription?: (newSegments: TranscriptionSegment[]) => void;
2428
/** amount of time (in ms) that the segment is considered `active` past its original segment duration, defaults to 2_000 */
2529
// maxAge?: number;
2630
}
@@ -46,6 +50,7 @@ export function useTrackTranscription(
4650
// const prevActiveSegments = React.useRef<ReceivedTranscriptionSegment[]>([]);
4751
const syncTimestamps = useTrackSyncTime(trackRef);
4852
const handleSegmentMessage = (newSegments: TranscriptionSegment[]) => {
53+
opts.onTranscription?.(newSegments);
4954
setSegments((prevSegments) =>
5055
dedupeSegments(
5156
prevSegments,

0 commit comments

Comments
 (0)