You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: articles/ai-services/openai/includes/text-to-speech-dotnet.md
+33-24Lines changed: 33 additions & 24 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -18,20 +18,6 @@ recommendations: false
18
18
19
19
## Set up
20
20
21
-
### Retrieve key and endpoint
22
-
23
-
To successfully make a call against Azure OpenAI, you need an **endpoint** and a **key**.
24
-
25
-
|Variable name | Value |
26
-
|--------------------------|-------------|
27
-
|`AZURE_OPENAI_ENDPOINT`| This value can be found in the **Keys & Endpoint** section when examining your resource from the Azure portal. Alternatively, you can find the value in the **Azure OpenAI Studio** > **Playground** > **Code View**. An example endpoint is: `https://aoai-docs.openai.azure.com/`.|
28
-
|`AZURE_OPENAI_API_KEY`| This value can be found in the **Keys & Endpoint** section when examining your resource from the Azure portal. You can use either `KEY1` or `KEY2`.|
29
-
30
-
Go to your resource in the Azure portal. The **Endpoint and Keys** can be found in the **Resource Management** section. Copy your endpoint and access key as you need both for authenticating your API calls. You can use either `KEY1` or `KEY2`. Always having two keys allows you to securely rotate and regenerate keys without causing a service disruption.
31
-
32
-
:::image type="content" source="../media/quickstarts/endpoint.png" alt-text="Screenshot of the overview UI for an Azure OpenAI resource in the Azure portal with the endpoint & access keys location highlighted." lightbox="../media/quickstarts/endpoint.png":::
33
-
34
-
35
21
## Create the .NET app
36
22
37
23
1. Create a .NET app using the `dotnet new` command:
@@ -46,17 +32,31 @@ Go to your resource in the Azure portal. The **Endpoint and Keys** can be found
46
32
cd OpenAISpeech
47
33
```
48
34
49
-
## Install the client library
35
+
1. Install the [`Azure.OpenAI`](https://www.nuget.org/packages/Azure.AI.OpenAI/) client library:
36
+
37
+
```dotnetcli
38
+
dotnet add package Azure.AI.OpenAI
39
+
```
40
+
41
+
## Authenticate and connect to Azure OpenAI
42
+
43
+
To make requests to your Azure OpenAI service, you need the service endpoint as well as authentication credentials via one of the following options:
44
+
45
+
- [Microsoft Entra ID](/entra/fundamentals/whatis) is the recommended approach for authenticating to Azure services and is more secure than key-based alternatives.
46
+
- Access keys allow you to provide a secret key to connect to your resource.
47
+
48
+
> [!IMPORTANT]
49
+
> Access keys should be used with caution. If your service access key is lost or accidentally exposed in an insecure location, your service may become vulnerable. Anyone who has the access key is able to authorize requests against the Azure OpenAI service.
50
+
51
+
### Get the Azure OpenAI endpoint
50
52
51
-
Install the [`Azure.OpenAI`](https://www.nuget.org/packages/Azure.AI.OpenAI/) client library:
53
+
The service endpoint can be found in the **Keys & Endpoint** section when examining your resource from the Azure portal. Alternatively, you can find the value in the **Azure OpenAI Studio** > **Playground** > **Code View**. An example endpoint is: `https://aoai-docs.openai.azure.com/`.
52
54
53
-
```dotnetcli
54
-
dotnet add package Azure.AI.OpenAI
55
-
```
55
+
:::image type="content" source="../media/quickstarts/endpoint.png" alt-text="Screenshot of the overview UI for an Azure OpenAI resource in the Azure portal with the endpoint & access keys location highlighted." lightbox="../media/quickstarts/endpoint.png":::
56
56
57
-
##Passwordless authentication is recommended
57
+
### Authenticate using Microsoft Entra ID
58
58
59
-
Passwordless authentication is more secure than key-based alternatives and is the recommended approach for connecting to Azure services. If you choose to use Passwordless authentication, you'll need to complete the following:
59
+
If you choose to use Microsoft Entra ID authentication, you'll need to complete the following:
60
60
61
61
1. Add the [`Azure.Identity`](https://www.nuget.org/packages/Azure.Identity) package.
62
62
@@ -67,6 +67,10 @@ Passwordless authentication is more secure than key-based alternatives and is th
67
67
1. Assign the `Cognitive Services User` role to your user account. This can be done in the Azure portal on your OpenAI resource under **Access control (IAM)** > **Add role assignment**.
68
68
1. Sign-in to Azure using Visual Studio or the Azure CLI via `az login`.
69
69
70
+
### Authenticate using keys
71
+
72
+
The access key value can be found in the **Keys & Endpoint** section when examining your resource from the Azure portal. You can use either `KEY1` or `KEY2`. Always having two keys allows you to securely rotate and regenerate keys without causing a service disruption.
73
+
70
74
## Update the app code
71
75
72
76
1. Replace the contents of `program.cs` with the following code and update the placeholder values with your own.
@@ -76,9 +80,14 @@ Passwordless authentication is more secure than key-based alternatives and is th
76
80
using Azure.AI.OpenAI;
77
81
using Azure.Identity; // Required for Passwordless auth
78
82
79
-
var endpoint = new Uri("YOUR_OPENAI_ENDPOINT");
80
-
var credentials = new AzureKeyCredential("YOUR_OPENAI_KEY");
81
-
// var credentials = new DefaultAzureCredential(); // Use this line for Passwordless auth
83
+
var endpoint = new Uri(
84
+
Environment.GetEnvironmentVariable("YOUR_OPENAI_ENDPOINT") ?? throw new ArgumentNullException());
85
+
var credentials = new DefaultAzureCredential();
86
+
87
+
// Use this line for key auth
88
+
// var credentials = new AzureKeyCredential(
89
+
// Environment.GetEnvironmentVariable("YOUR_OPENAI_KEY") ?? throw new ArgumentNullException());
90
+
82
91
var deploymentName = "tts"; // Default deployment name, update with your own if necessary
0 commit comments