
#  Translating with prompts

```
Exercise ID 1590073
```

##  Assignment 

The quality of Whisper's translation can vary depending on the language spoken, the audio quality, and the model's awareness of the subject matter. If you have any extra context about what is being spoken about, you can send it along with the audio to the model to give it a helping hand.

You've been provided with with an audio file, `audio.wav`; you're not sure what language is spoken in it, but you do know it relates to a recent World Bank report. Because you don't know how well the model will perform on this unknown language, you opt to send the model this extra context to steer it in the right direction.

##  Pre exercise code 

```
import shutil
import openai

# Copy file so learners don't need to add directory path
shutil.copy("/usr/local/share/datasets/mandarin-full.wav", "audio.wav")
```



##  Instructions 

- Assign your API key to `openai.api_key`.
- Open the [`audio.wav`](https://assets.datacamp.com/production/repositories/6309/datasets/c04d4830a7498cba96639e780cc7ef240b0d3033/mandarin-full.wav) file.
- Write a prompt that informs the model that the audio relates to a recent World Bank report, which will help the model produce an accurate translation.
- Create a request to the `Audio` endpoint to transcribe `audio.wav` using your `prompt`.



```
# Set your API key
openai.api_key = "____"

# Open the audio.wav file
audio_file = ____

# Write an appropriate prompt to help the model
prompt = "____"

# Create a translation from the audio file
response = ____

print(response["text"])
```

##  Hints 

- The `.translate()` method has a `prompt` argument that can be used to provide extra context or demonstrate the desired writing style to steer the model's output.



##  Solution 

```
# Set your API key
openai.api_key = "<OPENAI_API_TOKEN>"

# Open the audio.wav file
audio_file = open("audio.wav", "rb")

# Write an appropriate prompt to help the model
prompt = "The transcript contains a discussion on a recent World Bank Report."

# Create a translation from the audio file
response = openai.Audio.translate("whisper-1",
                                  audio_file,
                                  prompt=prompt)

print(response["text"])
```


