Skip to content

WhisperASR 类transcribe函数提示错误,已经修复,特此提醒给有需要的朋友 #339

@ncnynl

Description

@ncnynl

`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),即可正常使用。

Metadata

Metadata

Assignees

Labels

bug我的锅

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions