You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
subscription.unsubscribe(); // remember to unsubscribe
63
88
```
64
89
65
90
This is how an example closed caption looks like:
@@ -76,19 +101,6 @@ This is how an example closed caption looks like:
76
101
}
77
102
```
78
103
79
-
## Closed caption configuration
80
-
81
-
You can tweak the caption display logic using `updateClosedCaptionSettings` method:
82
-
83
-
```typescript
84
-
call.updateClosedCaptionSettings({
85
-
// The maximum number of closed captions to keep in the queue, default is 2
86
-
queueSize: 2,
87
-
// The time in milliseconds to keep a closed caption in the queue, default is 2700ms
88
-
retentionTimeInMs: 2700,
89
-
});
90
-
```
91
-
92
104
## See it in action
93
105
94
106
To see it all in action check out our TypeScript sample application on [GitHub](https://github.com/GetStream/stream-video-js/tree/main/sample-apps/client/ts-quickstart) or in [Codesandbox](https://codesandbox.io/p/sandbox/eloquent-glitter-99th3v).
description: How to add closed captions to your calls
5
5
---
6
6
7
-
The Stream API supports adding real-time closed captions (subtitles for participants) to your calls. This guide shows you how you can build it on top of our React SDK.
7
+
The Stream API supports adding real-time closed captions (subtitles for participants) to your calls.
8
+
This guide shows you how you can build it on top of our React SDK.
8
9
9
10
## Prerequisites
10
11
11
-
Make sure that the closed caption feature is enabled in your app's dashboard. The closed caption feature can be set on the call type level, and the available options are:
12
+
Make sure that the closed caption feature is enabled in your app's dashboard.
13
+
The closed caption feature can be set on the call type level, and the available options are:
12
14
13
15
-`available`: the feature is available for your call and can be enabled.
14
16
-`disabled`: the feature is not available for your call. In this case, it's a good idea to "hide" any UI element you have related to closed captions.
@@ -31,108 +33,72 @@ await call.getOrCreate({
31
33
32
34
For the purposes of this article, make sure that closed captions are either `available` or `auto-on`.
33
35
34
-
## Enablingand disabling closed caption events
36
+
## Enabling, disabling and tweaking closed captions
retentionTimeInMs: 2700, // the duration a caption can stay in the queue
44
+
queueSize: 2, // number of captions that can be stored in the queue
45
+
});
46
+
```
39
47
40
-
Let's start by building a custom hook that subscribes to and stores closed caption events.
48
+
## Check if closed captions are enabled
41
49
42
-
When displaying closed captions, we should make sure that they are real-time (showing a sentence from 30 seconds ago has very little use in a conversation) and visible for enough time that participants can read them. Finally, it makes sense to limit the total number of captions visible on the screen at once.
`Closed captions are ${isCaptioningInProgress?'enabled':'disabled'}`,
58
+
);
99
59
```
100
60
101
-
:::note
102
-
Since the closed caption event contains `start_time` and `end_time` fields, you can subtract the two to know how long it took the speaker to say the caption. You can then use this duration to control how long the text is visible on the screen. This is useful to ensure the captions are as real-time as possible, but that might not leave enough time for participants to read the text.
103
-
:::
104
-
105
-
## Displaying captions
61
+
## Rendering closed captions
106
62
107
-
Finally, we are ready to implement a component that renders captions:
63
+
Once enabled, the SDK will expose the closed caption events to your application via a special `useCallClosedCaptions` hook.
0 commit comments