Skip to content

Commit 5aa7f70

Browse files
authored
Merge pull request #272184 from valindrae/native-closed-captions-updates-pubp
Native closed captions updates pubp
2 parents 9bebfcb + 03026e5 commit 5aa7f70

File tree

4 files changed

+423
-137
lines changed

4 files changed

+423
-137
lines changed

articles/communication-services/quickstarts/voice-video-calling/get-started-with-closed-captions.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
title: Quickstart - Add closed captions to your app
33
titleSuffix: An Azure Communication Services quickstart
44
description: In this quickstart, you'll learn how to add closed captions to your existing calling app using Azure Communication Services.
5-
author: RinaRish
6-
ms.author: ektrishi
7-
ms.date: 02/02/2022
5+
author: Kunaal
6+
ms.author: kpunjabi
7+
ms.date: 04/15/2024
88
ms.topic: quickstart
99
ms.service: azure-communication-services
1010
ms.subservice: calling
11-
zone_pivot_groups: acs-plat-web-ios-android
11+
zone_pivot_groups: acs-plat-web-ios-android-windows
1212
ms.custom: mode-api, devx-track-js
1313
---
1414

@@ -21,6 +21,10 @@ ms.custom: mode-api, devx-track-js
2121
[!INCLUDE [Closed Captions for Web](./includes/closed-captions/closed-captions-javascript.md)]
2222
::: zone-end
2323

24+
::: zone pivot="platform-windows"
25+
[!INCLUDE [Video Calling with Windows](./includes/closed-captions/closed-captions-windows.md)]
26+
::: zone-end
27+
2428
::: zone pivot="platform-android"
2529
[!INCLUDE [Closed Captions for Android](./includes/closed-captions/closed-captions-android.md)]
2630
::: zone-end

articles/communication-services/quickstarts/voice-video-calling/includes/closed-captions/closed-captions-android.md

Lines changed: 129 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -2,103 +2,165 @@
22
title: Get started with Azure Communication Services closed caption on Android
33
titleSuffix: An Azure Communication Services quickstart document
44
description: Learn about the Azure Communication Services Closed Captions in Android apps
5-
author: RinaRish
6-
manager: visho
5+
author: Kunaal
76
services: azure-communication-services
8-
9-
ms.author: ektrishi
10-
ms.date: 02/03/2022
7+
ms.subservice: calling
8+
ms.author: valindrae
9+
ms.date: 04/15/2024
1110
ms.topic: include
1211
ms.service: azure-communication-services
1312
---
1413

1514
## Prerequisites
15+
- Azure account with an active subscription, for details see [Create an account for free.](https://azure.microsoft.com/free/)
16+
- Azure Communication Services resource. See [Create an Azure Communication Services resource](../../../../quickstarts/create-communication-resource.md?tabs=windows&pivots=platform-azp). Save the connection string for this resource.
17+
- An app with voice and video calling, refer to our [Voice](../../../../quickstarts/voice-video-calling/getting-started-with-calling.md) and [Video](../../../../quickstarts/voice-video-calling/get-started-with-video-calling.md) calling quickstarts.
1618

17-
Refer to the [Voice Calling Quickstart](../../getting-started-with-calling.md?pivots=platform-android) to set up a sample app with voice calling.
19+
>[!NOTE]
20+
>Please note that you will need to have a voice calling app using Azure Communication Services calling SDKs to access the closed captions feature that is described in this guide.
1821
1922
## Models
23+
| Name | Description |
24+
| ---------------------------------- | ----------------------------------------------------------------- |
25+
| CaptionsCallFeature | API for captions call feature |
26+
| CommunicationCaptions | API for communication captions |
27+
| StartCaptionOptions | Closed caption options like spoken language |
28+
| CommunicationCaptionsListener | Listener for CommunicationCaptions addOnCaptionsReceivedListener |
29+
| CommunicationCaptionsReceivedEvent | Data object received for each CommunicationCaptionsListener event |
30+
31+
## Get closed captions feature
32+
You need to get and cast the Captions object to utilize Captions specific features.
33+
34+
``` java
35+
CaptionsCallFeature captionsCallFeature = call.feature(Features.CAPTIONS);
36+
captionsCallFeature.getCaptions().whenComplete(
37+
((captions, throwable) -> {
38+
if (throwable == null) {
39+
CallCaptions callCaptions = captions;
40+
if (captions.getCaptionsType() == CaptionsType.COMMUNICATION_CAPTIONS) {
41+
// communication captions
42+
CommunicationCaptions communicationCaptions = (CommunicationCaptions) captions;
43+
}
44+
} else {
45+
// get captions failed
46+
// throwable is the exception/cause
47+
}
48+
}));
49+
```
2050

21-
| Name | Description |
22-
| - | - |
23-
| CaptionsCallFeature | Used to start and manage closed captions. |
24-
| StartCaptionsOptions | Used for representing options to start closed captions. |
25-
| CaptionsListener | Used to handle captions events. |
26-
| CaptionsInfo | Used to representing captions data. |
51+
## Subscribe to listeners
2752

28-
## Methods
29-
### Start captions
53+
### Add a listener to receive captions enabled/disabled status
3054

31-
1. Get the ongoing call object established during the prerequisite steps.
32-
2. Get the Captions Feature object
33-
```java
34-
CaptionsCallFeature captionsCallFeature = call.api(Features.CAPTIONS);
35-
```
36-
3. Define the CaptionsListener
37-
```java
38-
CaptionsListener captionsListener = new CaptionsListener() {
39-
@Override
40-
public void onCaptions(CaptionsInfo captionsInfo) {
41-
String captionsText = captionsInfo.getText(); // get transcribed text
42-
String speakerName = captionsInfo.getSpeaker().getDisplayName; // get display name of current speaker
43-
Date timeStamp = captionsInfo.getTimestamp(); // get timestamp corresponding to caption
44-
45-
// display captionsText and information as needed...
46-
}
47-
};
55+
``` java
56+
public void addOnIsCaptionsEnabledChangedListener() {
57+
communicationCaptions.addOnCaptionsEnabledChangedListener( (PropertyChangedEvent args) -> {
58+
if(communicationCaptions.isEnabled()) {
59+
// captions enabled
60+
}
61+
});
62+
}
4863
```
49-
4. Register the `captionsListener`
50-
5. Invoke `startCaptions` with the desired options.
51-
```java
52-
public void startCallCaptions() {
53-
captionsCallFeature.addOnCaptionsReceivedListener(captionsListener);
54-
if (!captionsCallFeature.isCaptionsActive) {
55-
StartCaptionsOptions startCaptionsOptions = new StartCaptionsOptions();
56-
startCaptionsOptions.setLanguage("en-us");
57-
58-
try {
59-
captionsCallFeature.startCaptions(startCaptionsOptions);
60-
} catch (Exception e) {
61-
e.printStackTrace();
64+
65+
### Add a listener to receive captions type changed
66+
This event will be triggered when the caption type changes from `CommunicationCaptions` to `TeamsCaptions` upon inviting Microsoft 365 users to ACS-only calls.
67+
68+
``` java
69+
public void addOnIsCaptionsTypeChangedListener() {
70+
captionsCallFeature.addOnActiveCaptionsTypeChangedListener( (PropertyChangedEvent args) -> {
71+
if(communicationCaptions.isEnabled()) {
72+
// captionsCallFeature.getCaptions();
6273
}
63-
}
74+
});
6475
}
6576
```
6677

78+
### Add listener for captions data received
79+
80+
``` java
81+
CommunicationCaptionsListener captionsListener = (CommunicationCaptionsReceivedEvent args) -> {
82+
// Information about the speaker.
83+
// CallerInfo participantInfo = args.getSpeaker();
84+
// The original text with no transcribed.
85+
// args.getSpokenText();
86+
// language identifier for the speaker.
87+
// args.getSpokenLanguage();
88+
// Timestamp denoting the time when the corresponding speech was made.
89+
// args.getTimestamp();
90+
// CaptionsResultType is Partial if text contains partially spoken sentence.
91+
// It is set to Final once the sentence has been completely transcribed.
92+
// args.getResultType() == CaptionsResultType.FINAL;
93+
};
94+
public void addOnCaptionsReceivedListener() {
95+
communicationCaptions.addOnCaptionsReceivedListener(captionsListener);
96+
}
97+
```
6798

68-
### Stopping captions
99+
### Add a listener to receive active spoken language changed status
69100

70-
Remove the previously registered `captionsListener`.
101+
``` java
102+
public void addOnActiveSpokenLanguageChangedListener() {
103+
communicationCaptions.addOnActiveSpokenLanguageChangedListener( (PropertyChangedEvent args) -> {
104+
// communicationCaptions.getActiveSpokenLanguage()
105+
});
106+
}
107+
```
71108

72-
```java
73-
public void stopCaptions() {
74-
captionsCallFeature.removeOnCaptionsReceivedListener(captionsListener);
109+
## Start captions
110+
111+
Once you've set up all your listeners, you can now start adding captions.
112+
113+
``` java
114+
public void startCaptions() {
115+
StartCaptionsOptions startCaptionsOptions = new StartCaptionsOptions();
116+
startCaptionsOptions.setSpokenLanguage("en-us");
117+
communicationCaptions.startCaptions(startCaptionsOptions).whenComplete((result, error) -> {
118+
if (error != null) {
119+
}
120+
});
75121
}
76122
```
77123

78-
### Get available languages
124+
## Stop captions
79125

80-
Call the `getAvailableLanguages` method on the `CaptionsCallFeature` API.
126+
``` java
127+
public void stopCaptions() {
128+
communicationCaptions.stopCaptions().whenComplete((result, error) -> {
129+
if (error != null) {
130+
}
131+
});
132+
}
133+
```
81134

82-
```java
83-
String[] captionsAvailableLanguages = captionsCallFeature.getAvailableLanguages();
135+
## Remove caption received listener
136+
137+
``` java
138+
public void removeOnCaptionsReceivedListener() {
139+
communicationCaptions.removeOnCaptionsReceivedListener(captionsListener);
140+
}
84141
```
85142

86-
### Update language
143+
## Spoken language support
144+
145+
### Get list of supported spoken languages
146+
Get a list of supported spoken languages that your users can select from when enabling closed captions.
87147

88-
Pass a value in from the available languages array to ensure that the requested language is supported.
148+
``` java
149+
// bcp 47 formatted language code
150+
communicationCaptions.getSupportedSpokenLanguages();
151+
```
152+
153+
### Set spoken language
154+
When the user selects the spoken language, your app can set the spoken language that it expects captions to be generated from.
89155

90-
```java
91-
public void switchCaptionsLanguage() {
92-
if (!captionsCallFeature.isCaptionsActive) {
93-
return;
94-
}
95-
try {
96-
captionsCallFeature.select(captionsAvailableLanguages[0]);
97-
} catch (Exception e) {
98-
e.printStackTrace();
99-
}
156+
``` java
157+
public void setSpokenLanguage() {
158+
communicationCaptions.setSpokenLanguage("en-us").whenComplete((result, error) -> {
159+
if (error != null) {
160+
}
161+
});
100162
}
101163
```
102164

103165
## Clean up
104-
Learn more about [cleaning up resources here.](../../../create-communication-resource.md?pivots=platform-azp&tabs=windows#clean-up-resources)
166+
Learn more about [cleaning up resources here.](../../../create-communication-resource.md?pivots=platform-azp&tabs=windows#clean-up-resources)

0 commit comments

Comments
 (0)