Skip to content

Commit 7984ed9

Browse files
Merge pull request #264172 from soferreira/patch-22
Add python whisper quickstart
2 parents 6b19a8c + 66e000f commit 7984ed9

File tree

3 files changed

+85
-1
lines changed

3 files changed

+85
-1
lines changed
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
---
2+
services: ai-services
3+
author: soferreira
4+
ms.author: soferreira
5+
ms.service: openai
6+
ms.topic: include
7+
ms.date: 1/25/2024
8+
---
9+
10+
## Python
11+
12+
### Prerequisites
13+
14+
- <a href="https://www.python.org/" target="_blank">Python 3.7.1 or later version</a>
15+
- The following Python libraries: os
16+
17+
### Set up
18+
19+
Install the OpenAI Python client library with:
20+
21+
# [OpenAI Python 0.28.1](#tab/python)
22+
23+
```console
24+
pip install openai==0.28.1
25+
```
26+
27+
# [OpenAI Python 1.x](#tab/python-new)
28+
29+
```console
30+
pip install openai
31+
```
32+
33+
---
34+
35+
1. Create a new Python file called quickstart.py. Then open it up in your preferred editor or IDE.
36+
37+
1. Replace the contents of quickstart.py with the following code. Modify the code to add your deployment name:
38+
39+
```python
40+
import openai
41+
import time
42+
import os
43+
44+
openai.api_key = os.getenv("AZURE_OPENAI_KEY")
45+
openai.api_base = os.getenv("AZURE_OPENAI_ENDPOINT") # your endpoint should look like the following https://YOUR_RESOURCE_NAME.openai.azure.com/
46+
openai.api_type = "azure"
47+
openai.api_version = "2023-09-01-preview"
48+
49+
model_name = "whisper"
50+
deployment_id = "YOUR-DEPLOYMENT-NAME-HERE" #This will correspond to the custom name you chose for your deployment when you deployed a model."
51+
audio_language="en"
52+
53+
audio_test_file = "./wikipediaOcelot.wav"
54+
55+
result = openai.Audio.transcribe(
56+
file=open(audio_test_file, "rb"),
57+
model=model_name,
58+
deployment_id=deployment_id
59+
)
60+
61+
print(result)
62+
```
63+
64+
Run the application with the python command on your quickstart file:
65+
66+
67+
You can get sample audio files from the [Azure AI Speech SDK repository at GitHub](https://github.com/Azure-Samples/cognitive-services-speech-sdk/tree/master/sampledata/audiofiles).
68+
69+
> [!IMPORTANT]
70+
> For production, use a secure way of storing and accessing your credentials like [Azure Key Vault](../../../key-vault/general/overview.md). For more information about credential security, see the Azure AI services [security](../../security-features.md) article.
71+
72+
## Output
73+
74+
```python
75+
{"text":"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."}
76+
```

articles/ai-services/openai/whisper-quickstart.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,12 @@ echo export AZURE_OPENAI_ENDPOINT="REPLACE_WITH_YOUR_ENDPOINT_HERE" >> /etc/envi
8989

9090
::: zone-end
9191

92+
::: zone pivot="programming-language-python"
93+
94+
[!INCLUDE [REST API quickstart](includes/whisper-python.md)]
95+
96+
::: zone-end
97+
9298
## Clean up resources
9399

94100
If you want to clean up and remove an OpenAI resource, you can delete the resource. Before deleting the resource, you must first delete any deployed models.

articles/zone-pivot-groups.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2004,6 +2004,8 @@ groups:
20042004
title: REST
20052005
- id: programming-language-powershell
20062006
title: PowerShell
2007+
- id: programming-language-python
2008+
title: Python
20072009
# Owner: diberry
20082010
- id: app-service-webjob
20092011
title: WebJob types
@@ -2996,4 +2998,4 @@ groups:
29962998
- id: programming-language-typescript
29972999
title: TypeScript
29983000
- id: programming-language-portal
2999-
title: Azure Portal
3001+
title: Azure Portal

0 commit comments

Comments
 (0)