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?
There are three possible reasons why you get AttributeError: module 'openai' has no attribute 'Audio'
.
The required Python version is 3.7.1
or newer, as stated in the official OpenAI GitHub repository.
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
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)