Skip to content

Commit 50130c3

Browse files
author
Xiting Zhang
committed
update speech service aad token support for java and python
1 parent ba02059 commit 50130c3

File tree

1 file changed

+64
-39
lines changed

1 file changed

+64
-39
lines changed

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

Lines changed: 64 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ For programming languages where a Microsoft identity platform client library isn
121121

122122
## Get the Speech resource ID
123123

124-
You need your Speech resource ID to make SDK calls using Microsoft Entra authentication.
124+
You need your Speech resource ID to make SDK calls using Microsoft Entra authentication in scenarios that don't yet support Entra ID directly.
125125

126126
# [Azure portal](#tab/portal)
127127

@@ -184,7 +184,7 @@ For ```SpeechRecognizer```, ```SourceLanguageRecognizer```, ```ConversationTrans
184184
TokenCredential browserCredential = new InteractiveBrowserCredential();
185185

186186
// Define the custom domain endpoint for your Speech resource.
187-
var endpoint = "wss://{your custom name}.cognitiveservices.azure.com/stt/speech/universal/v2";
187+
var endpoint = "https://{your custom name}.cognitiveservices.azure.com/";
188188

189189
// Create the SpeechConfig object using the custom domain endpoint and TokenCredential.
190190
var speechConfig = SpeechConfig.FromEndpoint(new Uri(endpoint), browserCredential);
@@ -198,7 +198,7 @@ For ```TranslationRecognizer``` object, use an appropriate instance of [TokenCre
198198
TokenCredential browserCredential = new InteractiveBrowserCredential();
199199

200200
// Define the custom domain endpoint for your Speech resource
201-
var endpoint = "wss://{your custom name}.cognitiveservices.azure.com/stt/speech/universal/v2";
201+
var endpoint = "https://{your custom name}.cognitiveservices.azure.com/";
202202

203203
// Create the SpeechTranslationConfig object using the custom domain endpoint and TokenCredential.
204204
var speechConfig = SpeechTranslationConfig.FromEndpoint(new Uri(endpoint), browserCredential);
@@ -233,38 +233,7 @@ std::string region = "Your Speech Region";
233233
auto authorizationToken = "aad#" + resourceId + "#" + aadToken;
234234
auto speechConfig = SpeechConfig::FromAuthorizationToken(authorizationToken, region);
235235
```
236-
::: zone-end
237-
238-
::: zone pivot="programming-language-java"
239-
### SpeechRecognizer, SpeechSynthesizer, IntentRecognizer, ConversationTranscriber
240-
241-
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.
242-
243-
```Java
244-
String resourceId = "Your Resource ID";
245-
String region = "Your Region";
246-
247-
// You need to include the "aad#" prefix and the "#" (hash) separator between resource ID and Microsoft Entra access token.
248-
String authorizationToken = "aad#" + resourceId + "#" + token;
249-
SpeechConfig speechConfig = SpeechConfig.fromAuthorizationToken(authorizationToken, region);
250-
```
251-
::: zone-end
252-
253-
::: zone pivot="programming-language-python"
254-
### SpeechRecognizer, SpeechSynthesizer, IntentRecognizer, ConversationTranscriber
255-
256-
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.
257-
258-
```Python
259-
resourceId = "Your Resource ID"
260-
region = "Your Region"
261-
# You need to include the "aad#" prefix and the "#" (hash) separator between resource ID and Microsoft Entra access token.
262-
authorizationToken = "aad#" + resourceId + "#" + aadToken.token
263-
speechConfig = SpeechConfig(auth_token=authorizationToken, region=region)
264-
```
265-
::: zone-end
266236

267-
::: zone pivot="programming-language-cpp"
268237
### TranslationRecognizer
269238

270239
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.
@@ -278,35 +247,91 @@ std::string region = "Your Speech Region";
278247
auto authorizationToken = "aad#" + resourceId + "#" + aadToken;
279248
auto speechConfig = SpeechTranslationConfig::FromAuthorizationToken(authorizationToken, region);
280249
```
250+
281251
::: zone-end
282252

283253
::: zone pivot="programming-language-java"
254+
### SpeechRecognizer, ConversationTranscriber
255+
256+
For ```SpeechRecognizer```, ```ConversationTranscriber``` objects, use an appropriate instance of [TokenCredential](/dotnet/api/azure.core.tokencredential) for authentication, along with the endpoint that includes your [custom domain](/azure/ai-services/speech-service/speech-services-private-link?tabs=portal#create-a-custom-domain-name), to create a ```SpeechConfig``` object.
257+
258+
```Java
259+
TokenCredential browserCredential = new InteractiveBrowserCredentialBuilder().build();
260+
261+
// Define the custom domain endpoint for your Speech resource.
262+
String endpoint = "https://{your custom name}.cognitiveservices.azure.com/";
263+
264+
// Create the SpeechConfig object using the custom domain endpoint and TokenCredential.
265+
SpeechConfig speechConfig = SpeechConfig.fromEndpoint(new java.net.URI(endpoint), browserCredential);
266+
```
267+
284268
### TranslationRecognizer
285269

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.
270+
For ```TranslationRecognizer``` object, use an appropriate instance of [TokenCredential](/dotnet/api/azure.core.tokencredential) for authentication, along with the endpoint that includes your [custom domain](/azure/ai-services/speech-service/speech-services-private-link?tabs=portal#create-a-custom-domain-name), to create a ```SpeechTranslationConfig``` object.
271+
272+
```Java
273+
TokenCredential browserCredential = new InteractiveBrowserCredentialBuilder().build();
274+
275+
// Define the custom domain endpoint for your Speech resource
276+
String endpoint = "https://{your custom name}.cognitiveservices.azure.com/";
277+
278+
// Create the SpeechTranslationConfig object using the custom domain endpoint and TokenCredential.
279+
SpeechConfig speechConfig = SpeechTranslationConfig.fromEndpoint(new java.net.URI(endpoint), browserCredential);
280+
```
281+
282+
### SpeechSynthesizer, IntentRecognizer
283+
284+
For ```SpeechSynthesizer```, ```IntentRecognizer``` objects, build the authorization token from the resource ID and the Microsoft Entra access token and then use it to create a ```SpeechConfig``` object.
287285

288286
```Java
289287
String resourceId = "Your Resource ID";
290288
String region = "Your Region";
291289

292290
// You need to include the "aad#" prefix and the "#" (hash) separator between resource ID and Microsoft Entra access token.
293291
String authorizationToken = "aad#" + resourceId + "#" + token;
294-
SpeechTranslationConfig translationConfig = SpeechTranslationConfig.fromAuthorizationToken(authorizationToken, region);
292+
SpeechConfig speechConfig = SpeechConfig.fromAuthorizationToken(authorizationToken, region);
295293
```
296294
::: zone-end
297295

298296
::: zone pivot="programming-language-python"
297+
### SpeechRecognizer, ConversationTranscriber
298+
299+
For ```SpeechRecognizer```, ```ConversationTranscriber``` objects, use an appropriate instance of [TokenCredential](/dotnet/api/azure.core.tokencredential) for authentication, along with the endpoint that includes your [custom domain](/azure/ai-services/speech-service/speech-services-private-link?tabs=portal#create-a-custom-domain-name), to create a ```SpeechConfig``` object.
300+
301+
```Python
302+
browserCredential = InteractiveBrowserCredential()
303+
304+
// Define the custom domain endpoint for your Speech resource.
305+
custom_endpoint = "https://{your custom name}.cognitiveservices.azure.com/"
306+
307+
// Create the SpeechConfig object using the custom domain endpoint and TokenCredential.
308+
speechConfig = SpeechConfig(token_credential=credential, endpoint=custom_endpoint)
309+
```
310+
299311
### TranslationRecognizer
300312

301-
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.
313+
For ```TranslationRecognizer``` object, use an appropriate instance of [TokenCredential](/dotnet/api/azure.core.tokencredential) for authentication, along with the endpoint that includes your [custom domain](/azure/ai-services/speech-service/speech-services-private-link?tabs=portal#create-a-custom-domain-name), to create a ```SpeechTranslationConfig``` object.
314+
315+
```Python
316+
browserCredential = InteractiveBrowserCredential()
317+
318+
// Define the custom domain endpoint for your Speech resource
319+
custom_endpoint = "https://{your custom name}.cognitiveservices.azure.com/"
320+
321+
// Create the SpeechTranslationConfig object using the custom domain endpoint and TokenCredential.
322+
speechTranslationConfig = SpeechTranslationConfig(token_credential=credential, endpoint=custom_endpoint)
323+
```
324+
325+
### SpeechSynthesizer, IntentRecognizer
326+
327+
For ```SpeechSynthesizer```, ```IntentRecognizer``` objects, build the authorization token from the resource ID and the Microsoft Entra access token and then use it to create a ```SpeechConfig``` object.
302328

303329
```Python
304330
resourceId = "Your Resource ID"
305331
region = "Your Region"
306-
307332
# You need to include the "aad#" prefix and the "#" (hash) separator between resource ID and Microsoft Entra access token.
308333
authorizationToken = "aad#" + resourceId + "#" + aadToken.token
309-
translationConfig = SpeechTranslationConfig(auth_token=authorizationToken, region=region)
334+
speechConfig = SpeechConfig(auth_token=authorizationToken, region=region)
310335
```
311336
::: zone-end
312337

0 commit comments

Comments
 (0)