There are three possible reasons why you get AttributeError: module 'openai' has no attribute 'Audio'.
Reason 1: You didn't upgrade Python
The required Python version is 3.7.1 or newer, as stated in the official OpenAI GitHub repository.
Reason 2: You didn't upgrade the OpenAI Python package
First, check your OpenAI package version by running the following command in the terminal:
pip show openai
You need to use version 0.27.0 or newer if you want to use the OpenAI Whisper API.
If you have an older package, run the following command in the terminal to update the OpenAI package:
pip install --upgrade openai
Reason 3: Your code isn't correct
Try the code below.
OPTION 1 (recommended):
test.py
import openai
import os
openai.api_key = os.getenv('OPENAI_API_KEY')
audio_file = open('audio.mp3', 'rb')
transcript = openai.Audio.transcribe('whisper-1', audio_file)
OPTION 2:
test.py
import openai
openai.api_key = 'sk-xxxxxxxxxxxxxxxxxxxx'
audio_file = open('audio.mp3', 'rb')
transcript = openai.Audio.transcribe('whisper-1', audio_file)