-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Open
Labels
bug我的锅我的锅
Description
`class WhisperASR(AbstractASR):
"""
OpenAI 的 whisper 语音识别API
"""
SLUG = "openai"
def __init__(self, openai_api_key, **args):
super(self.__class__, self).__init__()
try:
import openai
self.openai = openai
self.openai.api_key = openai_api_key
print(openai_api_key)
except Exception:
logger.critical("OpenAI 初始化失败,请升级 Python 版本至 > 3.6")
@classmethod
def get_config(cls):
return config.get("openai", {})
def transcribe(self, fp):
if self.openai:
try:
with open(fp, "rb") as f:
result = self.openai.Audio.transcribe("whisper-1", f)
if result:
logger.info(f"{self.SLUG} 语音识别到了:{result.text}")
return result.text
except Exception:
logger.critical(f"{self.SLUG} 语音识别出错了", stack_info=True)
return ""
logger.critical(f"{self.SLUG} 语音识别出错了", stack_info=True)
return ""`
把result = self.openai.Audio.transcribe("whisper-1", f),更改为result = self.openai.audio.transcriptions.create(model="whisper-1", file=f),即可正常使用。