Skip to content

Support gpt-4o-transcribe and gpt-4o-mini-transcribe #833

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

Merged
merged 3 commits into from
Mar 23, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 30 additions & 1 deletion speech_recognition/recognizers/whisper_api/openai.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
)

# https://platform.openai.com/docs/api-reference/audio/createTranscription#audio-createtranscription-model
WhisperModel = Literal["whisper-1"]
WhisperModel = Literal[
"whisper-1", "gpt-4o-transcribe", "gpt-4o-mini-transcribe"
]


class OpenAIOptionalParameters:
Expand Down Expand Up @@ -52,3 +54,30 @@ def recognize(

openai_recognizer = OpenAICompatibleRecognizer(openai.OpenAI())
return openai_recognizer.recognize(audio_data, model, **kwargs)


if __name__ == "__main__":
import argparse
from typing import get_args

import speech_recognition as sr

parser = argparse.ArgumentParser()
parser.add_argument("audio_file")
parser.add_argument(
"--model", choices=get_args(WhisperModel), default="whisper-1"
)
parser.add_argument("-l", "--language")
args = parser.parse_args()

r = sr.Recognizer()
with sr.AudioFile(args.audio_file) as source:
audio_data = r.listen(source)

if args.language:
transcription = recognize(
None, audio_data, model=args.model, language=args.language
)
else:
transcription = recognize(None, audio_data, model=args.model)
print(transcription)