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/whisper-dotnet.md
+50-49Lines changed: 50 additions & 49 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -32,77 +32,78 @@ Go to your resource in the Azure portal. The **Endpoint and Keys** can be found
32
32
33
33
1. Create a .NET app using the `dotnet new` command:
34
34
35
-
```dotnetcli
36
-
dotnet new console -n OpenAIWhisper
37
-
```
35
+
```dotnetcli
36
+
dotnet new console -n OpenAIWhisper
37
+
```
38
38
39
39
1. Change into the directory of the new app:
40
40
41
-
```dotnetcli
42
-
cd OpenAIWhisper
43
-
```
41
+
```dotnetcli
42
+
cd OpenAIWhisper
43
+
```
44
44
45
45
1. Install the [`Azure.OpenAI`](https://www.nuget.org/packages/Azure.AI.OpenAI/) client library:
46
46
47
-
```dotnetcli
48
-
dotnet add package Azure.AI.OpenAI
49
-
```
47
+
```dotnetcli
48
+
dotnet add package Azure.AI.OpenAI
49
+
```
50
50
51
51
## Passwordless authentication is recommended
52
52
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:
54
54
55
55
1. Add the [`Azure.Identity`](https://www.nuget.org/packages/Azure.Identity) package.
56
56
57
-
```dotnetcli
58
-
dotnet add package Azure.Identity
59
-
```
57
+
```dotnetcli
58
+
dotnet add package Azure.Identity
59
+
```
60
60
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**.
62
62
1. Sign-in to Azure using Visual Studio or the Azure CLI via `az login`.
63
63
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
-
usingAzure;
73
-
usingAzure.AI.OpenAI;
74
-
usingAzure.Identity; // Required for Passwordless auth
> 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).
97
97
98
98
1. Run the application using the `dotnet run` command:
99
99
100
-
```python
100
+
```dotnetcli
101
+
101
102
dotnet run
102
103
```
103
104
104
105
If you are using the sample audio file, you should see the following text printed out in the console:
105
106
106
-
``text
107
+
```text
107
108
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.
0 commit comments