#7076·spring-ai

When using ChatClient, the audio parameter of OpenAiChatOptions should be customizable rather than an enum

Author: zhujianxintianCreated Sep 29, 2026Updated Sep 29, 2026
Labelsstatus: waiting-for-triage

Since many service providers now support the OpenAI format, but outputAudio only accepts OpenAiChatOptions.AudioParameters, whose parameters are enums, this is very inflexible. Many providers have custom Voices, and their parameters differ from OpenAI's.

Currently, I have to implement my requirement as follows:

java
OpenAiChatOptions.Builder optionsBuilder = OpenAiChatOptions.builder()
        .model(speechProperties.getModel())
        // Use an enum placeholder first to ensure this parameter is set, so that the Spring AI underlying layer can access the audio parameters via request.audio(), and then convert according to the audio format
        .outputAudio(new OpenAiChatOptions.AudioParameters(OpenAiChatOptions.AudioParameters.Voice.ALLOY, OpenAiChatOptions.AudioParameters.AudioResponseFormat.WAV))
        // Then pass the actual third‑party service provider's Voice to replace the audio parameter, so that both the Spring AI underlying layer and the third‑party provider can obtain the parameters
        .extraBody(
                Map.of("audio", Map.of(
                        "format", OpenAiChatOptions.AudioParameters.AudioResponseFormat.WAV.name().toLowerCase(),
                        "voice", "Chloe"
                ))
        );

My suggestion is that, for AudioResponseFormat and Voice, at least Voice should be flexible—it could be a String plus provided OpenAI constants, or a class (similar to org.springframework.security.oauth2.core.AuthorizationGrantType) to replace the enum. For example:

java
// 1. String and OpenAI Voice constants
new OpenAiChatOptions.AudioParameters("Chloe", OpenAiChatOptions.AudioParameters.AudioResponseFormat.WAV);
// OpenAiChatOptions.AudioParameters.Voice.ALLOY is a String constant
new OpenAiChatOptions.AudioParameters(OpenAiChatOptions.AudioParameters.Voice.ALLOY, OpenAiChatOptions.AudioParameters.AudioResponseFormat.WAV);

// 2. Class (similar to org.springframework.security.oauth2.core.AuthorizationGrantType)
public final class Voice {

    public static final Voice ALLOY = new Voice("alloy");

    public static final Voice ASH = new Voice("ash");

    public static final Voice BALLAD = new Voice("ballad");


    // ... more


    private final String value;

    public Voice(String value) {
        Assert.hasText(value, "value cannot be empty");
        this.value = value;
    }

    public String getValue() {
        return this.value;
    }

}

new OpenAiChatOptions.AudioParameters(Voice.ALLOY, OpenAiChatOptions.AudioParameters.AudioResponseFormat.WAV);
new OpenAiChatOptions.AudioParameters(new Voice("Chloe"), OpenAiChatOptions.AudioParameters.AudioResponseFormat.WAV);

Of course, these are just my initial thoughts. If you have a better solution, that would be even better.


There is a similar issue (Voice parameter in SpeechRequest to be a free form text param instead of restricted enum, whose scenario seems to only target TextToSpeechModel, and it seems to have been resolved, while my issue is in the Chat scenario)

I also explained my issue under that issue very early on, but perhaps because that issue was raised earlier, the problem was buried, and it was not resolved for a long time, so I am raising a separate issue here for visibility

Source: spring-projects/spring-ai