Skip to content

Commit 9764976

Browse files
authored
Update whisper-python.md
1 parent ae7d4a8 commit 9764976

File tree

1 file changed

+75
-0
lines changed

1 file changed

+75
-0
lines changed
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +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+
---
19

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+
```

0 commit comments

Comments
 (0)