使用 Whisper API 生成 .SRT 脚本?

Saz*_*CoR 4 whisper openai-api openai-whisper

我正在探索 Whisper API 的功能,想知道它是否可以用于生成带有转录的 .SRT 文件。据我了解,使用 Whisper 包在本地运行模型时可以实现对 .SRT 的转录。不幸的是,我不具备在本地运行模型的计算资源,因此我倾向于直接使用 API。

有没有人有这方面的经验或者可以提供有关如何通过 API 处理它的指导?

import os
import openai
openai.api_key = API_KEY
audio_file = open("audio.mp3", "rb")
transcript = openai.Audio.transcribe("whisper-1", audio_file)
print(transcript.text)

Run Code Online (Sandbox Code Playgroud)

esq*_*qew 5

粗略浏览一下OpenAI 的文档就会发现这是端点上参数srt受支持的值。response_format/v1/audio/transcriptions

使用您在示例中使用的官方 Python 绑定,您应该能够将其作为命名参数传递给您的openai.Audio.transcribe()调用:

transcript = openai.Audio.transcribe("whisper-1", audio_file, response_format="srt")
Run Code Online (Sandbox Code Playgroud)