2

ChatGPT API is announced with Speech-to-text Whisper api and i was so excited to give it a try. Here's the link

I have tried their sample code

# Note: you need to be using OpenAI Python v0.27.0 for the code below to work
import openai

audio_file= open("/path/to/file/audio.mp3", "rb")

and got the following error

AttributeError: module 'openai' has no attribute 'Audio'

I'm sure i'm using the version 0.27.0

pip list | grep openai
openai                0.27.0

Do you think openai is not updated yet?

2 Answers 2

3

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)
Sign up to request clarification or add additional context in comments.

5 Comments

I'm using 3.10.7
I edited my answer. You have two options, but I recommend you to use the first one. Pick the second one only for testing purposes.
having the same issue. Didn't manage to solve so far. Just importing openai lib boomm! How did you solve it ?
@ThiagoC.SVentura Can you please check the OpenAI package version you're using? Use the pip show openai command.
I'm using python 3.8.10 and openai 1.1.1, but getting the same error.
0

While I was also facing this issue and and while I was trying to upgrade openai version i.e.0.27.0 by
pip install --upgrade openai it wasn't really upgrading.

So for that you can just following :

pip uninstall openai
pip install openai==0.27.0

So just we have to specify its version for install nothing much

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.