|
| 1 | +--- |
| 2 | +title: Get started with Azure Communication Services closed caption on Windows |
| 3 | +titleSuffix: An Azure Communication Services quickstart document |
| 4 | +description: Learn about the Azure Communication Services Closed Captions on Windows |
| 5 | +author: Kunaal |
| 6 | +services: azure-communication-services |
| 7 | +ms.subservice: calling |
| 8 | +ms.author: valindrae |
| 9 | +ms.date: 04/15/2024 |
| 10 | +ms.topic: include |
| 11 | +ms.service: azure-communication-services |
| 12 | +--- |
| 13 | +## Prerequisites |
| 14 | +- Azure account with an active subscription, for details see [Create an account for free.](https://azure.microsoft.com/free/) |
| 15 | +- 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. |
| 16 | +- 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. |
| 17 | + |
| 18 | +>[!NOTE] |
| 19 | +>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. |
| 20 | +
|
| 21 | +## Models |
| 22 | +| Name | Description | |
| 23 | +|----------------------------------------|------------------------------------------------------------------- | |
| 24 | +| CaptionsCallFeature | API for captions call feature | |
| 25 | +| CommunicationCaptions | API for communication captions | |
| 26 | +| StartCaptionOptions | Closed caption options like spoken language | |
| 27 | +| CommunicationCaptionsReceivedEventArgs | Data object received for each communication captions received event| |
| 28 | + |
| 29 | +## Get closed captions feature |
| 30 | +You need to get and cast the Captions object to utilize Captions specific features. |
| 31 | + |
| 32 | +``` cs |
| 33 | +CaptionsCallFeature captionsCallFeature = call.Features.Captions; |
| 34 | +CallCaptions callCaptions = await captionsCallFeature.GetCaptionsAsync(); |
| 35 | +if (callCaptions.CaptionsKind == CaptionsKind.CommunicationCaptions) |
| 36 | +{ |
| 37 | + CommunicationCaptions communicationCaptions = callCaptions as CommunicationCaptions; |
| 38 | +} |
| 39 | +``` |
| 40 | + |
| 41 | +## Subscribe to listeners |
| 42 | + |
| 43 | +### Add a listener to receive captions enabled/disabled status |
| 44 | + |
| 45 | +``` cs |
| 46 | +communicationCaptions.CaptionsEnabledChanged += OnIsCaptionsEnabledChanged; |
| 47 | + |
| 48 | +private void OnIsCaptionsEnabledChanged(object sender, PropertyChangedEventArgs args) |
| 49 | +{ |
| 50 | + if (communicationCaptions.IsEnabled) |
| 51 | + { |
| 52 | + } |
| 53 | +} |
| 54 | +``` |
| 55 | + |
| 56 | +### Add a listener to receive captions type changed |
| 57 | +This event will be triggered when the caption type changes from `CommunicationCaptions` to `TeamsCaptions` upon inviting Microsoft 365 users to ACS-only calls. |
| 58 | + |
| 59 | +``` cs |
| 60 | +captionsCallFeature.ActiveCaptionsTypeChanged += OnIsCaptionsTypeChanged; |
| 61 | + |
| 62 | +private void OnIsCaptionsTypeChanged(object sender, PropertyChangedEventArgs args) |
| 63 | +{ |
| 64 | + // get captions |
| 65 | +} |
| 66 | +``` |
| 67 | + |
| 68 | +### Add listener for captions data received |
| 69 | + |
| 70 | +``` cs |
| 71 | +communicationCaptions.CaptionsReceived += OnCaptionsReceived; |
| 72 | + |
| 73 | +private void OnCaptionsReceived(object sender, CommunicationCaptionsReceivedEventArgs eventArgs) |
| 74 | +{ |
| 75 | + // Information about the speaker. |
| 76 | + // eventArgs.Speaker |
| 77 | + // The original text with no transcribed. |
| 78 | + // eventArgs.SpokenText |
| 79 | + // language identifier for the speaker. |
| 80 | + // eventArgs.SpokenLanguage |
| 81 | + // Timestamp denoting the time when the corresponding speech was made. |
| 82 | + // eventArgs.Timestamp |
| 83 | + // CaptionsResultKind is Partial if text contains partially spoken sentence. |
| 84 | + // It is set to Final once the sentence has been completely transcribed. |
| 85 | + // eventArgs.ResultKind |
| 86 | +} |
| 87 | +``` |
| 88 | + |
| 89 | +### Add a listener to receive active spoken language changed status |
| 90 | + |
| 91 | +``` cs |
| 92 | +communicationCaptions.ActiveSpokenLanguageChanged += OnIsActiveSpokenLanguageChanged; |
| 93 | + |
| 94 | +private void OnIsActiveSpokenLanguageChanged(object sender, PropertyChangedEventArgs args) |
| 95 | +{ |
| 96 | + // communicationCaptions.ActiveSpokenLanguage |
| 97 | +} |
| 98 | +``` |
| 99 | + |
| 100 | +## Start captions |
| 101 | + |
| 102 | +Once you've set up all your listeners, you can now start adding captions. |
| 103 | + |
| 104 | +``` cs |
| 105 | + |
| 106 | +private async void StartCaptions() |
| 107 | +{ |
| 108 | + var options = new StartCaptionsOptions |
| 109 | + { |
| 110 | + SpokenLanguage = "en-us" |
| 111 | + }; |
| 112 | + try |
| 113 | + { |
| 114 | + await communicationCaptions.StartCaptionsAsync(options); |
| 115 | + } |
| 116 | + catch (Exception ex) |
| 117 | + { |
| 118 | + } |
| 119 | +} |
| 120 | +``` |
| 121 | + |
| 122 | +## Stop captions |
| 123 | + |
| 124 | +``` cs |
| 125 | +private async void StopCaptions() |
| 126 | +{ |
| 127 | + try |
| 128 | + { |
| 129 | + await communicationCaptions.StopCaptionsAsync(); |
| 130 | + } |
| 131 | + catch (Exception ex) |
| 132 | + { |
| 133 | + } |
| 134 | +} |
| 135 | +``` |
| 136 | + |
| 137 | +## Remove caption received listener |
| 138 | + |
| 139 | +``` cs |
| 140 | +communicationCaptions.CaptionsReceived -= OnCaptionsReceived; |
| 141 | +``` |
| 142 | + |
| 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. |
| 147 | + |
| 148 | +``` cs |
| 149 | +// bcp 47 formatted language code |
| 150 | +IReadOnlyList<string> sLanguages = communicationCaptions.SupportedSpokenLanguages;``` |
| 151 | + |
| 152 | +### Set spoken language |
| 153 | +When the user selects the spoken language, your app can set the spoken language that it expects captions to be generated from. |
| 154 | + |
| 155 | +``` cs |
| 156 | +public async void SetSpokenLanguage() |
| 157 | +{ |
| 158 | + try |
| 159 | + { |
| 160 | + await communicationCaptions.SetSpokenLanguageAsync("en-us"); |
| 161 | + } |
| 162 | + catch (Exception ex) |
| 163 | + { |
| 164 | + } |
| 165 | +} |
| 166 | +``` |
| 167 | + |
| 168 | +## Clean up |
| 169 | +Learn more about [cleaning up resources here.](../../../create-communication-resource.md?pivots=platform-azp&tabs=windows#clean-up-resources) |
0 commit comments