gpt4 book ai didi

python - OpenAI 耳语 API 错误 : "AttributeError: module ' openai' has no attribute 'Audio' "

转载 作者:行者123 更新时间:2023-12-02 05:47:04 27 4
gpt4 key购买 nike

ChatGPT API 与 Speech-to-text Whisper api 一起发布,我很高兴尝试一下。 Here's the link

我试过他们的示例代码

# 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")

出现如下错误

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

我确定我使用的是 0.27.0 版本

pip list | grep openai
openai 0.27.0

你觉得openai还没有更新吗?

最佳答案

您的代码不正确。

选项 1(推荐)

测试.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)

选项 2

测试.py

import openai

openai.api_key = 'sk-xxxxxxxxxxxxxxxxxxxx'

audio_file = open('audio.mp3', 'rb')
transcript = openai.Audio.transcribe('whisper-1', audio_file)

关于python - OpenAI 耳语 API 错误 : "AttributeError: module ' openai' has no attribute 'Audio' ",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/75609157/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com