Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
ncnynl opened this issue Sep 20, 2024 · 0 comments
Assignees
Labels
bug 我的锅

Comments

@ncnynl
Copy link

ncnynl commented Sep 20, 2024

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

@ncnynl ncnynl added the bug 我的锅 label Sep 20, 2024
@ncnynl ncnynl changed the title WhisperASR 的openai函数接口提示错误,已经修复,特此提醒给有需要的朋友 WhisperASR 类transcribe函数提示错误,已经修复,特此提醒给有需要的朋友 Sep 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 我的锅
Projects
None yet
Development

No branches or pull requests

2 participants