feat: add OpenAI-compatible POST /v1/audio/transcriptions endpoint - #234
Open
Kartvya69 wants to merge 1 commit into
Open
feat: add OpenAI-compatible POST /v1/audio/transcriptions endpoint#234Kartvya69 wants to merge 1 commit into
Kartvya69 wants to merge 1 commit into
Conversation
…BUHub#140) Wrap Gemini audio input into an OpenAI transcription API: - Hand-rolled multipart/form-data parser (no new dependencies, binary-safe) - Maps OpenAI fields: file -> inlineData, prompt/language -> prompt text - Response formats: json, text, verbose_json (OpenAI segment schema), srt, vtt with model-prompted [MM:SS.mmm -> MM:SS.mmm] timestamps - Audio duration estimation (MP3 frame walk incl. VBR, WAV, Ogg) for fallback segment end times - Fallback to single full-length segment when model omits timestamps - Reuses existing retry / account-switch / request-tracking pipeline Tested end-to-end against a live instance with gemini-3.7-flash on a short sound-effect MP3 in all five response formats.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #140
What
Exposes
POST /v1/audio/transcriptionsby wrapping Gemini's audio input capability into an OpenAI-compatible transcription API, so tools hardcoded to the OpenAI endpoint (e.g. OpenWhispr) work unmodified.How
multipart/form-dataparser (RFC 7578, binary-safe) — no new dependenciesinlineDatamodel→ Gemini model (suffix parsing reused)prompt→ guiding context for the transcriptionlanguage→ language hintresponse_format→ output encodingtemperaturenoted as out of scope for prompted transcriptionjson(default) →{"text": "..."}text→ plain textverbose_json→ OpenAI verbose schema (duration,language,segments[]withstart/end/text/...) — segment placeholder fields (tokens,avg_logprob, ...) are zeroed since prompted transcription cannot produce themsrt/vtt→ valid subtitle outputverbose_json/srt/vttan extra instruction asks the model to emit[MM:SS.mmm -> MM:SS.mmm] textlines, which are parsed into segments. If the model omits timestamps, falls back to a single segment spanning the audioOut of scope (as discussed in #140)
Streaming transcription, diarization. Timestamps come from model prompting, not a decoder — good but not sample-exact.
Testing
Tested end-to-end against a live instance (v1.3.5) with
gemini-3.7-flashon a short sound-effect MP3 (~1.8s):json→{"text":"Aaaaah!"}text→Aaaaah!verbose_json→{"duration":1.776,"segments":[{"start":0,"end":1.813,"text":"Fah!"}],...}srt/vtt→ valid timestamped subtitle outputfilefield →400 invalid_request_errorTranscribed wording varies between runs on ambiguous sound-effect audio (model interpretation), which matches expected prompted-transcription behavior.