Skip to content

Commit d6a79f0

Browse files
author
Qi Ding
committed
Merge remote-tracking branch 'origin/v-dingqi/doc_page_code_update' into staging
2 parents 976819f + 025ab2d commit d6a79f0

File tree

17 files changed

+153
-78
lines changed

17 files changed

+153
-78
lines changed
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
---
2+
author: eric-urban
3+
ms.service: azure-ai-speech
4+
ms.topic: include
5+
ms.date: 8/11/2024
6+
ms.author: eur
7+
---
8+
9+
You need to authenticate your application to access Azure AI services. This article shows you how to use environment variables to store your credentials. You can then access the environment variables from your code to authenticate your application. For production, use a more secure way to store and access your credentials.
10+
11+
[!INCLUDE [Azure key vault](~/reusable-content/ce-skilling/azure/includes/ai-services/security/microsoft-entra-id-akv-expanded.md)]
12+
13+
To set the environment variables for your Speech resource key and region, open a console window, and follow the instructions for your operating system and development environment.
14+
15+
- To set the `SPEECH_KEY` environment variable, replace *your-key* with one of the keys for your resource.
16+
- To set the `END_POINT` environment variable, replace *your-end-point* with one of the regions for your resource.
17+
18+
#### [Windows](#tab/windows)
19+
20+
```console
21+
setx SPEECH_KEY your-key
22+
setx END_POINT your-end-point
23+
```
24+
25+
> [!NOTE]
26+
> If you only need to access the environment variables in the current console, you can set the environment variable with `set` instead of `setx`.
27+
28+
After you add the environment variables, you might need to restart any programs that need to read the environment variables, including the console window. For example, if you're using Visual Studio as your editor, restart Visual Studio before you run the example.
29+
30+
#### [Linux](#tab/linux)
31+
32+
##### Bash
33+
34+
Edit your *.bashrc* file, and add the environment variables:
35+
36+
```bash
37+
export SPEECH_KEY=your-key
38+
export END_POINT=your-end-point
39+
```
40+
41+
After you add the environment variables, run `source ~/.bashrc` from your console window to make the changes effective.
42+
43+
#### [macOS](#tab/macos)
44+
45+
##### Bash
46+
47+
Edit your *.bash_profile* file, and add the environment variables:
48+
49+
```bash
50+
export SPEECH_KEY=your-key
51+
export END_POINT=your-end-point
52+
```
53+
54+
After you add the environment variables, run `source ~/.bash_profile` from your console window to make the changes effective.
55+
56+
##### Xcode
57+
58+
For iOS and macOS development, you set the environment variables in Xcode. For example, follow these steps to set the environment variable in Xcode 13.4.1.
59+
60+
1. Select **Product** > **Scheme** > **Edit scheme**.
61+
1. Select **Arguments** on the **Run** (Debug Run) page.
62+
1. Under **Environment Variables** select the plus (+) sign to add a new environment variable.
63+
1. Enter `SPEECH_KEY` for the **Name** and enter your Speech resource key for the **Value**.
64+
65+
To set the environment variable for your Speech resource region, follow the same steps. Set `END_POINT` to the endpoint of your resource. For example, `westus`.
66+
67+
68+
69+
For more configuration options, see [the Xcode documentation](https://help.apple.com/xcode/#/dev745c5c974).
70+
71+
---

articles/ai-services/speech-service/includes/quickstarts/speech-to-text-basics/cpp.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,16 +51,16 @@ Follow these steps to create a console application and install the Speech SDK.
5151
5252
int main()
5353
{
54-
// This example requires environment variables named "SPEECH_KEY" and "SPEECH_REGION"
54+
// This example requires environment variables named "SPEECH_KEY" and "END_POINT"
5555
auto speechKey = GetEnvironmentVariable("SPEECH_KEY");
56-
auto speechRegion = GetEnvironmentVariable("SPEECH_REGION");
56+
auto endPoint = GetEnvironmentVariable("END_POINT");
5757
58-
if ((size(speechKey) == 0) || (size(speechRegion) == 0)) {
59-
std::cout << "Please set both SPEECH_KEY and SPEECH_REGION environment variables." << std::endl;
58+
if ((size(speechKey) == 0) || (size(endPoint) == 0)) {
59+
std::cout << "Please set both SPEECH_KEY and END_POINT environment variables." << std::endl;
6060
return -1;
6161
}
6262
63-
auto speechConfig = SpeechConfig::FromSubscription(speechKey, speechRegion);
63+
auto speechConfig = SpeechConfig::FromEndpoint(speechKey, endPoint);
6464
6565
speechConfig->SetSpeechRecognitionLanguage("en-US");
6666
@@ -87,7 +87,7 @@ Follow these steps to create a console application and install the Speech SDK.
8787
{
8888
std::cout << "CANCELED: ErrorCode=" << (int)cancellation->ErrorCode << std::endl;
8989
std::cout << "CANCELED: ErrorDetails=" << cancellation->ErrorDetails << std::endl;
90-
std::cout << "CANCELED: Did you set the speech resource key and region values?" << std::endl;
90+
std::cout << "CANCELED: Did you set the speech resource key and endpoint values?" << std::endl;
9191
}
9292
}
9393
}
@@ -116,7 +116,7 @@ Follow these steps to create a console application and install the Speech SDK.
116116
1. [Build and run](/cpp/build/vscpp-step-2-build) your new console application to start speech recognition from a microphone.
117117

118118
> [!IMPORTANT]
119-
> Make sure that you set the `SPEECH_KEY` and `SPEECH_REGION` [environment variables](#set-environment-variables). If you don't set these variables, the sample fails with an error message.
119+
> Make sure that you set the `SPEECH_KEY` and `END_POINT` [environment variables](#set-environment-variables). If you don't set these variables, the sample fails with an error message.
120120
121121
1. Speak into your microphone when prompted. What you speak should appear as text:
122122

articles/ai-services/speech-service/includes/quickstarts/speech-to-text-basics/csharp.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,9 @@ Follow these steps to create a console application and install the Speech SDK.
5454

5555
class Program
5656
{
57-
// This example requires environment variables named "SPEECH_KEY" and "SPEECH_REGION"
57+
// This example requires environment variables named "SPEECH_KEY" and "END_POINT"
5858
static string speechKey = Environment.GetEnvironmentVariable("SPEECH_KEY");
59-
static string speechRegion = Environment.GetEnvironmentVariable("SPEECH_REGION");
59+
static string endPoint = Environment.GetEnvironmentVariable("END_POINT");
6060

6161
static void OutputSpeechRecognitionResult(SpeechRecognitionResult speechRecognitionResult)
6262
{
@@ -76,15 +76,15 @@ Follow these steps to create a console application and install the Speech SDK.
7676
{
7777
Console.WriteLine($"CANCELED: ErrorCode={cancellation.ErrorCode}");
7878
Console.WriteLine($"CANCELED: ErrorDetails={cancellation.ErrorDetails}");
79-
Console.WriteLine($"CANCELED: Did you set the speech resource key and region values?");
79+
Console.WriteLine($"CANCELED: Did you set the speech resource key and endpoint values?");
8080
}
8181
break;
8282
}
8383
}
8484

8585
async static Task Main(string[] args)
8686
{
87-
var speechConfig = SpeechConfig.FromSubscription(speechKey, speechRegion);
87+
var speechConfig = SpeechConfig.FromEndpoint(speechKey, endPoint);
8888
speechConfig.SpeechRecognitionLanguage = "en-US";
8989

9090
using var audioConfig = AudioConfig.FromDefaultMicrophoneInput();
@@ -106,7 +106,7 @@ Follow these steps to create a console application and install the Speech SDK.
106106
```
107107

108108
> [!IMPORTANT]
109-
> Make sure that you set the `SPEECH_KEY` and `SPEECH_REGION` [environment variables](#set-environment-variables). If you don't set these variables, the sample fails with an error message.
109+
> Make sure that you set the `SPEECH_KEY` and `END_POINT` [environment variables](#set-environment-variables). If you don't set these variables, the sample fails with an error message.
110110
111111
1. Speak into your microphone when prompted. What you speak should appear as text:
112112

articles/ai-services/speech-service/includes/quickstarts/speech-to-text-basics/java.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,12 @@ Follow these steps to create a console application for speech recognition.
7575
import java.util.concurrent.Future;
7676

7777
public class SpeechRecognition {
78-
// This example requires environment variables named "SPEECH_KEY" and "SPEECH_REGION"
78+
// This example requires environment variables named "SPEECH_KEY" and "END_POINT"
7979
private static String speechKey = System.getenv("SPEECH_KEY");
80-
private static String speechRegion = System.getenv("SPEECH_REGION");
80+
private static String endPoint = System.getenv("END_POINT");
8181

8282
public static void main(String[] args) throws InterruptedException, ExecutionException {
83-
SpeechConfig speechConfig = SpeechConfig.fromSubscription(speechKey, speechRegion);
83+
SpeechConfig speechConfig = SpeechConfig.fromEndpoint(speechKey, endPoint);
8484
speechConfig.setSpeechRecognitionLanguage("en-US");
8585
recognizeFromMicrophone(speechConfig);
8686
}
@@ -106,7 +106,7 @@ Follow these steps to create a console application for speech recognition.
106106
if (cancellation.getReason() == CancellationReason.Error) {
107107
System.out.println("CANCELED: ErrorCode=" + cancellation.getErrorCode());
108108
System.out.println("CANCELED: ErrorDetails=" + cancellation.getErrorDetails());
109-
System.out.println("CANCELED: Did you set the speech resource key and region values?");
109+
System.out.println("CANCELED: Did you set the speech resource key and endpoint values?");
110110
}
111111
}
112112

@@ -125,7 +125,7 @@ Follow these steps to create a console application for speech recognition.
125125
```
126126

127127
> [!IMPORTANT]
128-
> Make sure that you set the `SPEECH_KEY` and `SPEECH_REGION` [environment variables](#set-environment-variables). If you don't set these variables, the sample fails with an error message.
128+
> Make sure that you set the `SPEECH_KEY` and `END_POINT` [environment variables](#set-environment-variables). If you don't set these variables, the sample fails with an error message.
129129
130130
1. Speak into your microphone when prompted. What you speak should appear as text:
131131

articles/ai-services/speech-service/includes/quickstarts/speech-to-text-basics/python.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,9 @@ Follow these steps to create a console application.
4949
import azure.cognitiveservices.speech as speechsdk
5050

5151
def recognize_from_microphone():
52-
# This example requires environment variables named "SPEECH_KEY" and "SPEECH_REGION"
53-
speech_config = speechsdk.SpeechConfig(subscription=os.environ.get('SPEECH_KEY'), region=os.environ.get('SPEECH_REGION'))
52+
# This example requires environment variables named "SPEECH_KEY" and "END_POINT"
53+
# Replace with your own subscription key and endpoint, the endpoint is like : "https://YourServiceRegion.api.cognitive.microsoft.com"
54+
speech_config = speechsdk.SpeechConfig(subscription=os.environ.get('SPEECH_KEY'), endpoint=os.environ.get('END_POINT'))
5455
speech_config.speech_recognition_language="en-US"
5556

5657
audio_config = speechsdk.audio.AudioConfig(use_default_microphone=True)
@@ -68,7 +69,7 @@ Follow these steps to create a console application.
6869
print("Speech Recognition canceled: {}".format(cancellation_details.reason))
6970
if cancellation_details.reason == speechsdk.CancellationReason.Error:
7071
print("Error details: {}".format(cancellation_details.error_details))
71-
print("Did you set the speech resource key and region values?")
72+
print("Did you set the speech resource key and endpoint values?")
7273

7374
recognize_from_microphone()
7475
```
@@ -82,7 +83,7 @@ Follow these steps to create a console application.
8283
```
8384

8485
> [!IMPORTANT]
85-
> Make sure that you set the `SPEECH_KEY` and `SPEECH_REGION` [environment variables](#set-environment-variables). If you don't set these variables, the sample fails with an error message.
86+
> Make sure that you set the `SPEECH_KEY` and `END_POINT` [environment variables](#set-environment-variables). If you don't set these variables, the sample fails with an error message.
8687
8788
1. Speak into your microphone when prompted. What you speak should appear as text:
8889

articles/ai-services/speech-service/includes/quickstarts/speech-translation-basics/cpp.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,11 @@ Follow these steps to create a new console application and install the Speech SD
4545
4646
int main()
4747
{
48-
// This example requires environment variables named "SPEECH_KEY" and "SPEECH_REGION"
48+
// This example requires environment variables named "SPEECH_KEY" and "END_POINT"
4949
auto speechKey = GetEnvironmentVariable("SPEECH_KEY");
50-
auto speechRegion = GetEnvironmentVariable("SPEECH_REGION");
50+
auto endPoint = GetEnvironmentVariable("END_POINT");
5151
52-
auto speechTranslationConfig = SpeechTranslationConfig::FromSubscription(speechKey, speechRegion);
52+
auto speechTranslationConfig = SpeechTranslationConfig::FromEndpoint(speechKey, endPoint);
5353
speechTranslationConfig->SetSpeechRecognitionLanguage("en-US");
5454
speechTranslationConfig->AddTargetLanguage("it");
5555
@@ -82,7 +82,7 @@ Follow these steps to create a new console application and install the Speech SD
8282
{
8383
std::cout << "CANCELED: ErrorCode=" << (int)cancellation->ErrorCode << std::endl;
8484
std::cout << "CANCELED: ErrorDetails=" << cancellation->ErrorDetails << std::endl;
85-
std::cout << "CANCELED: Did you set the speech resource key and region values?" << std::endl;
85+
std::cout << "CANCELED: Did you set the speech resource key and endpoint values?" << std::endl;
8686
}
8787
}
8888
}

articles/ai-services/speech-service/includes/quickstarts/speech-translation-basics/csharp.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ The Speech SDK is available as a [NuGet package](https://www.nuget.org/packages/
1919

2020
### Set environment variables
2121

22-
[!INCLUDE [Environment variables](../../common/environment-variables.md)]
22+
[!INCLUDE [Environment variables](../../common/environment-variables-endpoint-key.md)]
2323

2424
## Translate speech from a microphone
2525

@@ -45,9 +45,9 @@ Follow these steps to create a new console application and install the Speech SD
4545
4646
class Program
4747
{
48-
// This example requires environment variables named "SPEECH_KEY" and "SPEECH_REGION"
48+
// This example requires environment variables named "SPEECH_KEY" and "END_POINT"
4949
static string speechKey = Environment.GetEnvironmentVariable("SPEECH_KEY");
50-
static string speechRegion = Environment.GetEnvironmentVariable("SPEECH_REGION");
50+
static string endPoint = Environment.GetEnvironmentVariable("END_POINT");
5151
5252
static void OutputSpeechRecognitionResult(TranslationRecognitionResult translationRecognitionResult)
5353
{
@@ -71,15 +71,15 @@ Follow these steps to create a new console application and install the Speech SD
7171
{
7272
Console.WriteLine($"CANCELED: ErrorCode={cancellation.ErrorCode}");
7373
Console.WriteLine($"CANCELED: ErrorDetails={cancellation.ErrorDetails}");
74-
Console.WriteLine($"CANCELED: Did you set the speech resource key and region values?");
74+
Console.WriteLine($"CANCELED: Did you set the speech resource key and endpoint values?");
7575
}
7676
break;
7777
}
7878
}
7979
8080
async static Task Main(string[] args)
8181
{
82-
var speechTranslationConfig = SpeechTranslationConfig.FromSubscription(speechKey, speechRegion);
82+
var speechTranslationConfig = SpeechTranslationConfig.FromEndpoint(speechKey, endPoint);
8383
speechTranslationConfig.SpeechRecognitionLanguage = "en-US";
8484
speechTranslationConfig.AddTargetLanguage("it");
8585

articles/ai-services/speech-service/includes/quickstarts/speech-translation-basics/java.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,12 @@ Follow these steps to create a new console application for speech recognition.
7474
import java.util.Map;
7575

7676
public class SpeechTranslation {
77-
// This example requires environment variables named "SPEECH_KEY" and "SPEECH_REGION"
77+
// This example requires environment variables named "SPEECH_KEY" and "END_POINT"
7878
private static String speechKey = System.getenv("SPEECH_KEY");
79-
private static String speechRegion = System.getenv("SPEECH_REGION");
79+
private static String endPoint = System.getenv("END_POINT");
8080

8181
public static void main(String[] args) throws InterruptedException, ExecutionException {
82-
SpeechTranslationConfig speechTranslationConfig = SpeechTranslationConfig.fromSubscription(speechKey, speechRegion);
82+
SpeechTranslationConfig speechTranslationConfig = SpeechTranslationConfig.fromEndpoint(speechKey, endPoint);
8383
speechTranslationConfig.setSpeechRecognitionLanguage("en-US");
8484

8585
String[] toLanguages = { "it" };
@@ -114,7 +114,7 @@ Follow these steps to create a new console application for speech recognition.
114114
if (cancellation.getReason() == CancellationReason.Error) {
115115
System.out.println("CANCELED: ErrorCode=" + cancellation.getErrorCode());
116116
System.out.println("CANCELED: ErrorDetails=" + cancellation.getErrorDetails());
117-
System.out.println("CANCELED: Did you set the speech resource key and region values?");
117+
System.out.println("CANCELED: Did you set the speech resource key and endpoint values?");
118118
}
119119
}
120120

articles/ai-services/speech-service/includes/quickstarts/speech-translation-basics/python.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,9 @@ Follow these steps to create a new console application.
4242
import azure.cognitiveservices.speech as speechsdk
4343
4444
def recognize_from_microphone():
45-
# This example requires environment variables named "SPEECH_KEY" and "SPEECH_REGION"
46-
speech_translation_config = speechsdk.translation.SpeechTranslationConfig(subscription=os.environ.get('SPEECH_KEY'), region=os.environ.get('SPEECH_REGION'))
45+
# This example requires environment variables named "SPEECH_KEY" and "END_POINT"
46+
# Replace with your own subscription key and endpoint, the endpoint is like : "https://YourServiceRegion.api.cognitive.microsoft.com"
47+
speech_translation_config = speechsdk.translation.SpeechTranslationConfig(subscription=os.environ.get('SPEECH_KEY'), endpoint=os.environ.get('END_POINT'))
4748
speech_translation_config.speech_recognition_language="en-US"
4849
4950
to_language ="it"
@@ -67,7 +68,7 @@ Follow these steps to create a new console application.
6768
print("Speech Recognition canceled: {}".format(cancellation_details.reason))
6869
if cancellation_details.reason == speechsdk.CancellationReason.Error:
6970
print("Error details: {}".format(cancellation_details.error_details))
70-
print("Did you set the speech resource key and region values?")
71+
print("Did you set the speech resource key and endpoint values?")
7172
7273
recognize_from_microphone()
7374
```

0 commit comments

Comments
 (0)