
#  Translating Portuguese

```
Exercise ID 1590072
```

##  Assignment 

Whisper can not only transcribe audio into its native language but also supports translation capabilities for creating English transcriptions.

In this exercise, you'll return to the Portuguese audio, but this time, you'll translate it into English!

##  Pre exercise code 

```
import shutil
import openai

# Copy file so learners don't need to add directory path
shutil.copy("/usr/local/share/datasets/audio-portuguese.m4a", "audio.m4a")
```



##  Instructions 

- Assign your API key to `openai.api_key`.
- Open the [`audio.m4a`](https://assets.datacamp.com/production/repositories/6309/datasets/443390237150862833705a6e0599478575a1276a/audio-portuguese.m4a) file.
- Create a translation request to the Audio endpoint.
- Extract and print the translated text from the response.



```
# Set your API key
openai.api_key = "____"

# Open the audio.m4a file
audio_file = ____(____, "rb")

# Create a translation from the audio file
response = openai.Audio.____(____, ____)

# Extract and print the translated text
print(____)
```

##  Hints 

- Assign your API key to `openai.api_key` and create a request to Moderation endpoint using the `openai` package and the `Audio.translate()` function.



##  Solution 

```
# Set your API key
openai.api_key = "<OPENAI_API_TOKEN>"

# Open the audio.m4a file
audio_file = open("audio.m4a", "rb")

# Create a translation from the audio file
response = openai.Audio.translate("whisper-1", audio_file)

# Extract and print the translated text
print(response["text"])
```


