Skip to content

Commit dd55856

Browse files
committed
Add OpenAI TTS Voice Unit Test
1 parent 8148b0a commit dd55856

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020

2121
import org.junit.jupiter.api.Test;
2222
import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable;
23+
import org.junit.jupiter.params.ParameterizedTest;
24+
import org.junit.jupiter.params.provider.ValueSource;
2325
import reactor.core.publisher.Flux;
2426

2527
import org.springframework.ai.openai.OpenAiAudioSpeechOptions;
@@ -111,4 +113,21 @@ void shouldStreamNonEmptyResponsesForValidSpeechPrompts() {
111113
assertThat(response.getResult().getOutput()).isNotEmpty());
112114
}
113115

116+
@ParameterizedTest(name = "{0} : {displayName} ")
117+
@ValueSource(strings = {"alloy", "echo", "fable", "onyx", "nova", "shimmer", "sage", "coral", "ash"})
118+
void speechVoicesTest(String voice) {
119+
OpenAiAudioSpeechOptions speechOptions = OpenAiAudioSpeechOptions.builder()
120+
.voice(OpenAiAudioApi.SpeechRequest.Voice.valueOf(voice.toUpperCase()))
121+
.speed(SPEED)
122+
.responseFormat(OpenAiAudioApi.SpeechRequest.AudioResponseFormat.MP3)
123+
.model(OpenAiAudioApi.TtsModel.TTS_1.value)
124+
.build();
125+
SpeechPrompt speechPrompt = new SpeechPrompt("Today is a wonderful day to build something people love!",
126+
speechOptions);
127+
SpeechResponse response = this.speechModel.call(speechPrompt);
128+
byte[] audioBytes = response.getResult().getOutput();
129+
assertThat(response.getResults()).hasSize(1);
130+
assertThat(response.getResults().get(0).getOutput()).isNotEmpty();
131+
assertThat(audioBytes).hasSizeGreaterThan(0);
132+
}
114133
}

0 commit comments

Comments
 (0)