Skip to content

fix(audio): treat DIARIZED_JSON as a JSON response format (#652)#744

Open
spor3006 wants to merge 1 commit into
openai:mainfrom
spor3006:fix/652-diarized-json-isjson
Open

fix(audio): treat DIARIZED_JSON as a JSON response format (#652)#744
spor3006 wants to merge 1 commit into
openai:mainfrom
spor3006:fix/652-diarized-json-isjson

Conversation

@spor3006
Copy link
Copy Markdown

Fixes #652.

Problem

AudioResponseFormat.isJson() was missing a DIARIZED_JSON -> true branch:

internal fun isJson(): Boolean =
    when (this) {
        JSON -> true
        TEXT -> false
        SRT -> false
        VERBOSE_JSON -> true
        VTT -> false
        else -> false   // ← DIARIZED_JSON silently fell through to false
    }

When a caller requested response_format = DIARIZED_JSON from audio.transcriptions().create(...), the SDK treated the response as plain text. The entire diarized JSON payload was stuffed into TranscriptionCreateResponse.transcription.text, leaving TranscriptionCreateResponse.diarized empty. The only workaround was to manually re-parse the raw text field through Jackson:

new ObjectMapper().readValue(
    response.transcription().get().text(),
    TranscriptionDiarized.class
);

Fix

Two small changes:

  1. Add the missing case to AudioResponseFormat.isJson():
    DIARIZED_JSON -> true
  2. Add AudioResponseFormatTest that enumerates every value of AudioResponseFormat.Known explicitly and asserts the expected isJson() return value. Because the test exhaustively switches on Known, adding any new format to the enum will fail compilation of the test until the test author explicitly chooses true or false for it. The same class of bug cannot regress.

Tests

$ ./gradlew :openai-java-core:test --tests "com.openai.models.audio.AudioResponseFormatTest"

AudioResponseFormatTest > isJson_returnsTrue_forEveryJsonResponseFormat PASSED
AudioResponseFormatTest > diarizedJson_isReportedAsJson PASSED

Verified the second test (diarizedJson_isReportedAsJson) fails on main without the production change — the response would be reported as non-JSON.

Scope

  • Only AudioResponseFormat.kt (one line) and the new test file change. No public API surface change.
  • The TranscriptionCreateResponse.isValid() follow-up symptom noted in the issue (server-side response missing required fields per the OpenAPI spec) is left out — that's a spec/server question, not an SDK bug.

Fixes #652

AudioResponseFormat.isJson() omitted DIARIZED_JSON from its when()
branches and fell through to the `else -> false` default. As a result,
`AudioTranscriptionService.create(...)` with `response_format =
DIARIZED_JSON` parsed the response body as plain text — the entire
diarized JSON payload was dropped into
`TranscriptionCreateResponse.transcription.text` instead of populating
`TranscriptionCreateResponse.diarized`. Callers had to round-trip the
text field through an external Jackson reader to recover the structured
result.

Add `DIARIZED_JSON -> true` to isJson() and add an
AudioResponseFormatTest that enumerates every value of
AudioResponseFormat.Known explicitly, so any future format added to the
enum forces a conscious decision about whether it is JSON — the same
class of bug cannot regress when a new format is introduced.

Fixes openai#652

Signed-off-by: Sparshal Kothari <41056517+spor3006@users.noreply.github.com>
@spor3006 spor3006 requested a review from a team as a code owner May 19, 2026 18:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Transcription API response is missing diarized data for response_format=diarized_json

1 participant