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

L1-L2正则化的不同系数

我想对网络的权重同时应用L1和L2正则化。然而,我找不…

使用scikit-learn的无监督方法将列表分类成不同组别,有没有办法?

我有一系列实例,每个实例都有一份列表,代表它所遵循的不…

f1_score metric in lightgbm

我想使用自定义指标f1_score来训练一个lgb模型…

通过相关系数矩阵进行特征选择

我在测试不同的算法时,如逻辑回归、高斯朴素贝叶斯、随机…

可以将机器学习库用于流式输入和输出吗?

已关闭。此问题需要更加聚焦。目前不接受回答。 想要改进…

在TensorFlow中,queue.dequeue_up_to()方法的用途是什么?

我对这个方法感到非常困惑,特别是当我发现这个令人费解的…

发表回复

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