Skip to content

Commit e322c5f

Browse files
committed
fixes
1 parent 2983ae8 commit e322c5f

File tree

1 file changed

+50
-49
lines changed

1 file changed

+50
-49
lines changed

articles/ai-services/openai/includes/whisper-dotnet.md

Lines changed: 50 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -32,77 +32,78 @@ Go to your resource in the Azure portal. The **Endpoint and Keys** can be found
3232

3333
1. Create a .NET app using the `dotnet new` command:
3434

35-
```dotnetcli
36-
dotnet new console -n OpenAIWhisper
37-
```
35+
```dotnetcli
36+
dotnet new console -n OpenAIWhisper
37+
```
3838
3939
1. Change into the directory of the new app:
4040
41-
```dotnetcli
42-
cd OpenAIWhisper
43-
```
41+
```dotnetcli
42+
cd OpenAIWhisper
43+
```
4444
4545
1. Install the [`Azure.OpenAI`](https://www.nuget.org/packages/Azure.AI.OpenAI/) client library:
4646
47-
```dotnetcli
48-
dotnet add package Azure.AI.OpenAI
49-
```
47+
```dotnetcli
48+
dotnet add package Azure.AI.OpenAI
49+
```
5050
5151
## Passwordless authentication is recommended
5252
53-
Passwordless authentication is more secure than the key-based alternatives and the recommended approach for connecting to Azure services. If you choose to use Passwordless authentication, you'll need to complete the following:
53+
Passwordless authentication is more secure than the 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:
5454
5555
1. Add the [`Azure.Identity`](https://www.nuget.org/packages/Azure.Identity) package.
5656
57-
```dotnetcli
58-
dotnet add package Azure.Identity
59-
```
57+
```dotnetcli
58+
dotnet add package Azure.Identity
59+
```
6060
61-
1. Assign the `Cognitive Services User` role to your user account. This can be done in the Azure portal under **Access control (IAM)** > **Add role assignment**.
61+
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**.
6262
1. Sign-in to Azure using Visual Studio or the Azure CLI via `az login`.
6363
64-
## Create the app code
65-
66-
1. Replace the contents of `program.cs` with the following code and update the placeholder values with your own:
67-
68-
> [!NOTE]
69-
> You can get sample audio files, such as *wikipediaOcelot.wav*, from the [Azure AI Speech SDK repository at GitHub](https://github.com/Azure-Samples/cognitive-services-speech-sdk/tree/master/sampledata/audiofiles).
70-
71-
```csharp
72-
using Azure;
73-
using Azure.AI.OpenAI;
74-
using Azure.Identity; // Required for Passwordless auth
75-
76-
var endpoint = new Uri("YOUR_OPENAI_ENDPOINT");
77-
var credentials = new AzureKeyCredential("YOUR_OPENAI_KEY");
78-
// var credentials = new DefaultAzureCredential(); // Use for Passwordless auth
79-
var deploymentName = "whisper"; // Default name, update with your own if necessary
80-
var audioFilePath = "YOUR_AUDIO_FILE_PATH";
81-
82-
var openAIClient = new AzureOpenAIClient(endpoint, credentials);
83-
84-
var audioClient = openAIClient.GetAudioClient(deploymentName);
85-
86-
var result = await audioClient.TranscribeAudioAsync(audioFilePath);
87-
88-
Console.WriteLine("Transcribed text:");
89-
foreach (var item in result.Value.Text)
90-
{
91-
Console.Write(item);
92-
}
93-
```
94-
95-
> [!IMPORTANT]
96-
> For production, store and access your credentials using a secure method, such as [Azure Key Vault](/azure/key-vault/general/overview). For more information about credential security, see [Azure AI services security](../../security-features.md).
64+
## Update the app code
65+
66+
1. Replace the contents of `program.cs` with the following code and update the placeholder values with your own.
67+
68+
> [!NOTE]
69+
> You can get sample audio files, such as *wikipediaOcelot.wav*, from the [Azure AI Speech SDK repository at GitHub](https://github.com/Azure-Samples/cognitive-services-speech-sdk/tree/master/sampledata/audiofiles).
70+
71+
```csharp
72+
using Azure;
73+
using Azure.AI.OpenAI;
74+
using Azure.Identity; // Required for Passwordless auth
75+
76+
var endpoint = new Uri("YOUR_OPENAI_ENDPOINT");
77+
var credentials = new AzureKeyCredential("YOUR_OPENAI_KEY");
78+
// var credentials = new DefaultAzureCredential(); // Use this line for Passwordless auth
79+
var deploymentName = "whisper"; // Default deployment name, update with your own if necessary
80+
var audioFilePath = "YOUR_AUDIO_FILE_PATH";
81+
82+
var openAIClient = new AzureOpenAIClient(endpoint, credentials);
83+
84+
var audioClient = openAIClient.GetAudioClient(deploymentName);
85+
86+
var result = await audioClient.TranscribeAudioAsync(audioFilePath);
87+
88+
Console.WriteLine("Transcribed text:");
89+
foreach (var item in result.Value.Text)
90+
{
91+
Console.Write(item);
92+
}
93+
```
94+
95+
> [!IMPORTANT]
96+
> For production, store and access your credentials using a secure method, such as [Azure Key Vault](/azure/key-vault/general/overview). For more information about credential security, see [Azure AI services security](../../security-features.md).
9797
9898
1. Run the application using the `dotnet run` command:
9999
100-
```python
100+
```dotnetcli
101+
101102
dotnet run
102103
```
103104

104105
If you are using the sample audio file, you should see the following text printed out in the console:
105106

106-
``text
107+
```text
107108
The ocelot, Lepardus paradalis, is a small wild cat native to the southwestern United States, Mexico, and Central and South America. This medium-sized cat is characterized by solid black spots and streaks on its coat, round ears, and white neck and undersides. It weighs between 8 and 15.5 kilograms, 18 and 34 pounds, and reaches 40 to 50 centimeters 16 to 20 inches at the shoulders. It was first described by Carl Linnaeus in 1758. Two subspecies are recognized, L. p. paradalis and L. p. mitis. Typically active during twilight and at night, the ocelot tends to be solitary and territorial. It is efficient at climbing, leaping, and swimming. It preys on small terrestrial mammals such as armadillo, opossum, and lagomorphs.
108109
```

0 commit comments

Comments
 (0)