Skip to content

Commit 64a4f79

Browse files
gabriel duncanilayaperumalg
authored andcommitted
Add missing audio formats for OpenAIAudio API
- Add missing formats "wav" and "pcm" which OpenAI supports but SpringAI does not have serializers for Signed-off-by: gabriel duncan <gabrielduncan@Mac.attlocal.net>
1 parent 4f4da30 commit 64a4f79

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

models/spring-ai-openai/src/main/java/org/springframework/ai/openai/api/OpenAiAudioApi.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -378,8 +378,8 @@ public String getValue() {
378378
}
379379

380380
/**
381-
* The format to audio in. Supported formats are mp3, opus, aac, and flac.
382-
* Defaults to mp3.
381+
* The format to audio in. Supported formats are mp3, opus, aac, wav, pcm and
382+
* flac. Defaults to mp3.
383383
*/
384384
public enum AudioResponseFormat {
385385

@@ -391,7 +391,11 @@ public enum AudioResponseFormat {
391391
@JsonProperty("aac")
392392
AAC("aac"),
393393
@JsonProperty("flac")
394-
FLAC("flac");
394+
FLAC("flac"),
395+
@JsonProperty("wav")
396+
WAV("wav"),
397+
@JsonProperty("pcm")
398+
PCM("pcm");
395399
// @formatter:on
396400

397401
public final String value;

models/spring-ai-openai/src/test/java/org/springframework/ai/openai/audio/speech/OpenAiSpeechModelIT.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,24 @@ void shouldGenerateNonEmptyMp3AudioFromSpeechPrompt() {
7272

7373
}
7474

75+
@Test
76+
void shouldGenerateNonEmptyWavAudioFromSpeechPrompt() {
77+
OpenAiAudioSpeechOptions speechOptions = OpenAiAudioSpeechOptions.builder()
78+
.voice(OpenAiAudioApi.SpeechRequest.Voice.ALLOY)
79+
.speed(SPEED)
80+
.responseFormat(OpenAiAudioApi.SpeechRequest.AudioResponseFormat.WAV)
81+
.model(OpenAiAudioApi.TtsModel.TTS_1.value)
82+
.build();
83+
SpeechPrompt speechPrompt = new SpeechPrompt("Today is a wonderful day to build something people love!",
84+
speechOptions);
85+
SpeechResponse response = this.speechModel.call(speechPrompt);
86+
byte[] audioBytes = response.getResult().getOutput();
87+
assertThat(response.getResults()).hasSize(1);
88+
assertThat(response.getResults().get(0).getOutput()).isNotEmpty();
89+
assertThat(audioBytes).hasSizeGreaterThan(0);
90+
91+
}
92+
7593
@Test
7694
void speechRateLimitTest() {
7795
OpenAiAudioSpeechOptions speechOptions = OpenAiAudioSpeechOptions.builder()

0 commit comments

Comments
 (0)