OpenAI Whisper API错误:”AttributeError: module ‘openai’ has no attribute ‘Audio'”

ChatGPT API发布了语音转文本的Whisper API,我非常兴奋地尝试了一下。这是链接

我尝试了他们的示例代码

# Note: you need to be using OpenAI Python v0.27.0 for the code below to workimport openaiaudio_file= open("/path/to/file/audio.mp3", "rb")

然后得到了以下错误

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

我确定我使用的是0.27.0版本

pip list | grep openaiopenai                0.27.0

你认为openai还没有更新吗?


回答:

你遇到AttributeError: module 'openai' has no attribute 'Audio'的原因可能有以下三种。

原因1:你没有升级Python

官方OpenAI GitHub仓库中指出,需要使用3.7.1或更新的Python版本。

原因2:你没有升级OpenAI Python包

首先,在终端中运行以下命令检查你的OpenAI包版本:

pip show openai

如果你想使用OpenAI Whisper API,你需要使用0.27.0或更新的版本。

如果你使用的是旧版本,在终端中运行以下命令来更新OpenAI包:

pip install --upgrade openai

原因3:你的代码不正确

尝试以下代码。

选项1(推荐):

test.py

import openaiimport osopenai.api_key = os.getenv('OPENAI_API_KEY')audio_file = open('audio.mp3', 'rb')transcript = openai.Audio.transcribe('whisper-1', audio_file)

选项2:

test.py

import openaiopenai.api_key = 'sk-xxxxxxxxxxxxxxxxxxxx'audio_file = open('audio.mp3', 'rb')transcript = openai.Audio.transcribe('whisper-1', audio_file)

Related Posts

使用LSTM在Python中预测未来值

这段代码可以预测指定股票的当前日期之前的值,但不能预测…

如何在gensim的word2vec模型中查找双词组的相似性

我有一个word2vec模型,假设我使用的是googl…

dask_xgboost.predict 可以工作但无法显示 – 数据必须是一维的

我试图使用 XGBoost 创建模型。 看起来我成功地…

ML Tuning – Cross Validation in Spark

我在https://spark.apache.org/…

如何在React JS中使用fetch从REST API获取预测

我正在开发一个应用程序,其中Flask REST AP…

如何分析ML.NET中多类分类预测得分数组?

我在ML.NET中创建了一个多类分类项目。该项目可以对…

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注