Skip to content

Commit 66b6894

Browse files
author
Xiting Zhang
committed
Authentication via aad token credential
1 parent c77ff37 commit 66b6894

File tree

1 file changed

+45
-11
lines changed

1 file changed

+45
-11
lines changed

articles/ai-services/speech-service/how-to-configure-azure-ad-auth.md

Lines changed: 45 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -175,11 +175,26 @@ With a Microsoft Entra access token, you can now create a Speech SDK configurati
175175

176176
The method of providing the token, and the method to construct the corresponding Speech SDK ```Config``` object varies by the object you're using.
177177

178-
### SpeechRecognizer, SpeechSynthesizer, IntentRecognizer, ConversationTranscriber
178+
::: zone pivot="programming-language-csharp"
179+
### SpeechRecognizer, SourceLanguageRecognizer, ConversationTranscriber
179180

180-
For ```SpeechRecognizer```, ```SpeechSynthesizer```, ```IntentRecognizer```, ```ConversationTranscriber``` objects, build the authorization token from the resource ID and the Microsoft Entra access token and then use it to create a ```SpeechConfig``` object.
181+
For ```SpeechRecognizer```, ```SourceLanguageRecognizer```, ```ConversationTranscriber``` objects, use an instance of ```TokenCredential``` along with the endpoint that includes your custom domain to create a ```SpeechConfig``` object.
182+
183+
```C#
184+
// Use an appropriate [credential derived from TokenCredential](https://learn.microsoft.com/dotnet/api/azure.core.tokencredential) based on your authentication scenario.
185+
TokenCredential browserCredential = new InteractiveBrowserCredential();
186+
187+
// Define the custom domain endpoint for your Speech resource. Learn more about [creating a custom domain](https://learn.microsoft.com/azure/ai-services/speech-service/speech-services-private-link?tabs=portal#create-a-custom-domain-name)
188+
var endpoint = wss://{your custom name}.cognitiveservices.azure.com/stt/speech/universal/v2";
189+
190+
// Create the SpeechConfig object using the custom domain endpoint and TokenCredential.
191+
var speechConfig = SpeechConfig.FromEndpoint(new Uri(endpoint), browserCredential);
192+
```
193+
194+
### SpeechSynthesizer
195+
196+
For ```SpeechSynthesizer``` objects, build the authorization token from the resource ID and the Microsoft Entra access token and then use it to create a ```SpeechConfig``` object.
181197

182-
::: zone pivot="programming-language-csharp"
183198
```C#
184199
string resourceId = "Your Resource ID";
185200
string aadToken = "Your Microsoft Entra access token";
@@ -192,6 +207,10 @@ var speechConfig = SpeechConfig.FromAuthorizationToken(authorizationToken, regio
192207
::: zone-end
193208

194209
::: zone pivot="programming-language-cpp"
210+
### SpeechRecognizer, SpeechSynthesizer, IntentRecognizer, ConversationTranscriber
211+
212+
For ```SpeechRecognizer```, ```SpeechSynthesizer```, ```IntentRecognizer```, ```ConversationTranscriber``` objects, build the authorization token from the resource ID and the Microsoft Entra access token and then use it to create a ```SpeechConfig``` object.
213+
195214
```C++
196215
std::string resourceId = "Your Resource ID";
197216
std::string aadToken = "Your Microsoft Entra access token";
@@ -204,6 +223,10 @@ auto speechConfig = SpeechConfig::FromAuthorizationToken(authorizationToken, reg
204223
::: zone-end
205224

206225
::: zone pivot="programming-language-java"
226+
### SpeechRecognizer, SpeechSynthesizer, IntentRecognizer, ConversationTranscriber
227+
228+
For ```SpeechRecognizer```, ```SpeechSynthesizer```, ```IntentRecognizer```, ```ConversationTranscriber``` objects, build the authorization token from the resource ID and the Microsoft Entra access token and then use it to create a ```SpeechConfig``` object.
229+
207230
```Java
208231
String resourceId = "Your Resource ID";
209232
String region = "Your Region";
@@ -215,6 +238,10 @@ SpeechConfig speechConfig = SpeechConfig.fromAuthorizationToken(authorizationTok
215238
::: zone-end
216239

217240
::: zone pivot="programming-language-python"
241+
### SpeechRecognizer, SpeechSynthesizer, IntentRecognizer, ConversationTranscriber
242+
243+
For ```SpeechRecognizer```, ```SpeechSynthesizer```, ```IntentRecognizer```, ```ConversationTranscriber``` objects, build the authorization token from the resource ID and the Microsoft Entra access token and then use it to create a ```SpeechConfig``` object.
244+
218245
```Python
219246
resourceId = "Your Resource ID"
220247
region = "Your Region"
@@ -226,21 +253,24 @@ speechConfig = SpeechConfig(auth_token=authorizationToken, region=region)
226253

227254
### TranslationRecognizer
228255

229-
For the ```TranslationRecognizer```, build the authorization token from the resource ID and the Microsoft Entra access token and then use it to create a ```SpeechTranslationConfig``` object.
230-
231256
::: zone pivot="programming-language-csharp"
257+
For ```TranslationRecognizer``` objects, build the authorization token from the resource ID and the Microsoft Entra access token and then use it to create a ```SpeechTranslationConfig``` object.
258+
232259
```C#
233-
string resourceId = "Your Resource ID";
234-
string aadToken = "Your Microsoft Entra access token";
235-
string region = "Your Speech Region";
260+
// Use an appropriate [credential derived from TokenCredential](https://learn.microsoft.com/dotnet/api/azure.core.tokencredential) based on your authentication scenario.
261+
TokenCredential browserCredential = new InteractiveBrowserCredential();
236262

237-
// You need to include the "aad#" prefix and the "#" (hash) separator between resource ID and Microsoft Entra access token.
238-
var authorizationToken = $"aad#{resourceId}#{aadToken}";
239-
var speechConfig = SpeechTranslationConfig.FromAuthorizationToken(authorizationToken, region);
263+
// Define the custom domain endpoint for your Speech resource. Learn more about [creating a custom domain](https://learn.microsoft.com/azure/ai-services/speech-service/speech-services-private-link?tabs=portal#create-a-custom-domain-name)
264+
var endpoint = wss://{your custom name}.cognitiveservices.azure.com/stt/speech/universal/v2";
265+
266+
// Create the SpeechTranslationConfig object using the custom domain endpoint and TokenCredential.
267+
var speechConfig = SpeechTranslationConfig.FromEndpoint(new Uri(endpoint), browserCredential);
240268
```
241269
::: zone-end
242270

243271
::: zone pivot="programming-language-cpp"
272+
For the ```TranslationRecognizer```, build the authorization token from the resource ID and the Microsoft Entra access token and then use it to create a ```SpeechTranslationConfig``` object.
273+
244274
```cpp
245275
std::string resourceId = "Your Resource ID";
246276
std::string aadToken = "Your Microsoft Entra access token";
@@ -253,6 +283,8 @@ auto speechConfig = SpeechTranslationConfig::FromAuthorizationToken(authorizatio
253283
::: zone-end
254284

255285
::: zone pivot="programming-language-java"
286+
For the ```TranslationRecognizer```, build the authorization token from the resource ID and the Microsoft Entra access token and then use it to create a ```SpeechTranslationConfig``` object.
287+
256288
```Java
257289
String resourceId = "Your Resource ID";
258290
String region = "Your Region";
@@ -264,6 +296,8 @@ SpeechTranslationConfig translationConfig = SpeechTranslationConfig.fromAuthoriz
264296
::: zone-end
265297

266298
::: zone pivot="programming-language-python"
299+
For the ```TranslationRecognizer```, build the authorization token from the resource ID and the Microsoft Entra access token and then use it to create a ```SpeechTranslationConfig``` object.
300+
267301
```Python
268302
resourceId = "Your Resource ID"
269303
region = "Your Region"

0 commit comments

Comments
 (0)