|
1 | 1 | ---
|
2 |
| -title: Get started with Azure Communication Services closed caption on iOS |
| 2 | +title: Get started with Azure Communication Services closed caption on Android |
3 | 3 | titleSuffix: An Azure Communication Services quickstart document
|
4 |
| -description: Learn about the Azure Communication Services Closed Captions in iOS apps |
5 |
| -author: RinaRish |
6 |
| -manager: visho |
| 4 | +description: Learn about the Azure Communication Services Closed Captions in Android apps |
| 5 | +author: Kunaal |
7 | 6 | 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 |
11 | 10 | ms.topic: include
|
12 | 11 | ms.service: azure-communication-services
|
13 | 12 | ---
|
14 | 13 |
|
15 | 14 | ## 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. |
16 | 18 |
|
17 |
| -Refer to the [Voice Calling Quickstart](../../getting-started-with-calling.md?pivots=platform-ios) 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. |
18 | 21 |
|
19 | 22 | ## 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 | +| CommunicationCaptionsDelegate | Delegate for communication captions | |
| 29 | +| CommunicationCaptionsReceivedEventArgs | Data object received for each communication captions received event | |
| 30 | + |
| 31 | +## Get closed captions feature |
| 32 | +You need to get and cast the Captions object to utilize Captions specific features. |
| 33 | + |
| 34 | +``` swift |
| 35 | +if let call = self.call { |
| 36 | + @State var captionsCallFeature = call.feature(Features.captions) |
| 37 | + captionsCallFeature.getCaptions{(value, error) in |
| 38 | + if let error = error { |
| 39 | + // failed to get captions |
| 40 | + } else { |
| 41 | + if (value?.type == CaptionsType.communicationCaptions) { |
| 42 | + // communication captions |
| 43 | + @State var communicationCaptions = value as? CommunicationCaptions |
| 44 | + } |
| 45 | + } |
| 46 | + } |
| 47 | +} |
| 48 | +``` |
20 | 49 |
|
21 |
| -| Name | Description | |
22 |
| -| - | - | |
23 |
| -| CaptionsCallFeature | Used to start and manage closed captions. | |
24 |
| -| StartCaptionsOptions | Used for representing options to start closed captions. | |
25 |
| -| CaptionsCallFeatureDelegate | Used to handle captions events. | |
26 |
| -| CaptionsInfo | Used to representing captions data. | |
| 50 | +## Subscribe to listeners |
27 | 51 |
|
28 |
| -## Methods |
| 52 | +### Add a listener to receive captions enabled/disabled, type, spoken language, caption language status changed and data received |
29 | 53 |
|
30 |
| -### Start captions |
| 54 | +The event `didChangeActiveCaptionsType` will be triggered when the caption type changes from `CommunicationCaptions` to `TeamsCaptions` upon inviting Microsoft 365 users to ACS-only calls. |
31 | 55 |
|
32 |
| -1. Get the ongoing call object established during the prerequisite steps. |
33 |
| -2. Get the Captions Feature object |
34 |
| -```swift |
35 |
| -var captionsFeature = self.call!.feature(Features.captions) |
36 |
| -``` |
37 |
| -3. Define the CaptionsCallFeatureDelegate |
38 | 56 | ```swift
|
39 |
| -@State var callObserver:CallObserver? |
40 |
| -extension CallObserver: CaptionsCallFeatureDelegate { |
41 |
| - init(view:<nameOfView>) { |
42 |
| - owner = view |
43 |
| - super.init() |
| 57 | +extension CallObserver: CommunicationCaptionsDelegate { |
| 58 | + // listener for receive captions enabled/disabled status |
| 59 | + public func communicationCaptions(_ communicationCaptions: CommunicationCaptions, didChangeCaptionsEnabledState args: PropertyChangedEventArgs) { |
| 60 | + // communicationCaptions.isEnabled |
44 | 61 | }
|
45 |
| - public func captionsCallFeature(_ captionsFeature: CaptionsCallFeature, didChangeCaptionsState args: PropertyChangedEventArgs) { |
46 |
| - os_log("Call captions state changed to %d", log:log, captionsFeature.isCaptionsActive) |
| 62 | + |
| 63 | + // listener for active spoken language state change |
| 64 | + public func communicationCaptions(_ communicationCaptions: CommunicationCaptions, didChangeActiveSpokenLanguageState args: PropertyChangedEventArgs) { |
| 65 | + // communicationCaptions.activeSpokenLanguage |
47 | 66 | }
|
48 | 67 |
|
49 |
| - public func captionsCallFeature(_ captionsFeature: CaptionsCallFeature, didReceiveCaptions: CaptionsInfo) { |
50 |
| - let formatter = DateFormatter() |
51 |
| - formatter.dateStyle = .short |
52 |
| - formatter.timeStyle = .short |
53 |
| - let displayedTime = formatter.string(from: didReceiveCaptions.timestamp) |
54 |
| - let captionsText = "\(displayedTime) \(didReceiveCaptions.speaker.displayName): \(didReceiveCaptions.text)" |
55 |
| - // next display captionsText |
| 68 | + // listener for captions data received |
| 69 | + public func communicationCaptions(_ communicationCaptions: CommunicationCaptions, didReceiveCaptions:CommunicationCaptionsReceivedEventArgs) { |
| 70 | + // Information about the speaker. |
| 71 | + // didReceiveCaptions.speaker |
| 72 | + // The original text with no transcribed. |
| 73 | + // didReceiveCaptions.spokenText |
| 74 | + // language identifier for the speaker. |
| 75 | + // didReceiveCaptions.spokenLanguage |
| 76 | + // Timestamp denoting the time when the corresponding speech was made. |
| 77 | + // didReceiveCaptions.timestamp |
| 78 | + // CaptionsResultType is Partial if text contains partially spoken sentence. |
| 79 | + // It is set to Final once the sentence has been completely transcribed. |
| 80 | + // didReceiveCaptions.resultType |
56 | 81 | }
|
57 | 82 | }
|
58 |
| -self.callObserver = CallObserver(view:self) |
| 83 | + |
| 84 | +communicationCaptions.delegate = self.callObserver |
| 85 | + |
| 86 | +extension CallObserver: CaptionsCallFeatureDelegate { |
| 87 | + // captions type changed |
| 88 | + public func captionsCallFeature(_ captionsCallFeature: CaptionsCallFeature, didChangeActiveCaptionsType args: PropertyChangedEventArgs) { |
| 89 | + // captionsCallFeature.getCaptions to get captions |
| 90 | + } |
| 91 | +} |
| 92 | + |
| 93 | +captionsCallFeature.delegate = self.callObserver |
59 | 94 | ```
|
60 |
| -4. Register the captions feature delegate. |
61 |
| -5. Invoke `startCaptions` with the desired options. |
62 |
| -```swift |
| 95 | + |
| 96 | +## Start captions |
| 97 | + |
| 98 | +Once you've set up all your listeners, you can now start adding captions. |
| 99 | + |
| 100 | +``` swift |
63 | 101 | func startCaptions() {
|
64 |
| - captionsFeature!.delegate = self.callObserver |
65 |
| - if(!captionsFeature!.isCaptionsActive) { |
66 |
| - let startCaptionsOptions = StartCaptionsOptions() |
67 |
| - startCaptionsOptions.language = "en-us" |
68 |
| - captionsFeature!.startCaptions(startCaptionsOptions: startCaptionsOptions, completionHandler: { (error) in |
69 |
| - if (error != nil) { |
70 |
| - print ("Call captions Failed to start caption %@", error! as Error) |
71 |
| - } |
72 |
| - }) |
| 102 | + guard let communicationCaptions = communicationCaptions else { |
| 103 | + return |
73 | 104 | }
|
| 105 | + let startCaptionsOptions = StartCaptionsOptions() |
| 106 | + startCaptionsOptions.spokenLanguage = "en-us" |
| 107 | + communicationCaptions.startCaptions(startCaptionsOptions: startCaptionsOptions, completionHandler: { (error) in |
| 108 | + if error != nil { |
| 109 | + |
| 110 | + } |
| 111 | + }) |
74 | 112 | }
|
75 | 113 | ```
|
76 | 114 |
|
77 |
| -### Stopping captions |
78 |
| - |
79 |
| -Remove the previously registered delegate. |
| 115 | +## Stop captions |
80 | 116 |
|
81 |
| -```swift |
| 117 | +``` swift |
82 | 118 | func stopCaptions() {
|
83 |
| - captionsFeature?.delegate = nil |
| 119 | + communicationCaptions.stopCaptions(completionHandler: { (error) in |
| 120 | + if error != nil { |
| 121 | + |
| 122 | + } |
| 123 | + }) |
84 | 124 | }
|
85 | 125 | ```
|
86 | 126 |
|
87 |
| -### Get available languages |
88 |
| - |
89 |
| -Access the `availableLanguages` property on the `CaptionsCallFeature` API. |
| 127 | +## Remove caption received listener |
90 | 128 |
|
91 |
| -```swift |
92 |
| -var captionsAvailableLanguages = captionsFeature!.availableLanguages |
| 129 | +``` swift |
| 130 | +communicationCaptions?.delegate = nil |
93 | 131 | ```
|
94 | 132 |
|
95 |
| -### Update language |
| 133 | +## Spoken language support |
96 | 134 |
|
97 |
| -Pass a value in from the available languages array to ensure that the requested language is supported. |
| 135 | +### Get list of supported spoken languages |
| 136 | +Get a list of supported spoken languages that your users can select from when enabling closed captions. |
98 | 137 |
|
99 |
| -```swift |
100 |
| -func switchCaptionsLanguage() { |
101 |
| - if (!captionsFeature!.isCaptionsActive) { |
| 138 | +``` swift |
| 139 | +// bcp 47 formatted language code |
| 140 | +let spokenLanguage : String = "en-us" |
| 141 | +for language in communicationCaptions?.supportedSpokenLanguages ?? [] { |
| 142 | + // choose required language |
| 143 | + spokenLanguage = language |
| 144 | +} |
| 145 | +``` |
| 146 | + |
| 147 | +### Set spoken language |
| 148 | +When the user selects the spoken language, your app can set the spoken language that it expects captions to be generated from. |
| 149 | + |
| 150 | +``` swift |
| 151 | +func setSpokenLanguage() { |
| 152 | + guard let communicationCaptions = self.communicationCaptions else { |
102 | 153 | return
|
103 | 154 | }
|
104 |
| - captionsFeature!.select(language: captionsAvailableLanguages[0], completionHandler: { (error) in |
105 |
| - if (error != nil) { |
106 |
| - print ("Call captions Failed to switch language %@", error! as Error) |
| 155 | + |
| 156 | + communicationCaptions.set(spokenLanguage: spokenLanguage, completionHandler: { (error) in |
| 157 | + if let error = error { |
107 | 158 | }
|
108 | 159 | })
|
109 | 160 | }
|
110 | 161 | ```
|
111 | 162 |
|
112 | 163 | ## Clean up
|
113 |
| -Learn more about [cleaning up resources here.](../../../create-communication-resource.md?pivots=platform-azp&tabs=windows#clean-up-resources) |
| 164 | +Learn more about [cleaning up resources here.](../../../create-communication-resource.md?pivots=platform-azp&tabs=windows#clean-up-resources) |
0 commit comments