Skip to content

Commit 6122b2a

Browse files
committed
Fix OpenAiAudioApi javadoc
1 parent ccd5767 commit 6122b2a

File tree

1 file changed

+10
-30
lines changed

1 file changed

+10
-30
lines changed

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

Lines changed: 10 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,7 @@ public String getValue() {
9494
}
9595

9696
/**
97-
* Request to generates audio from the input text.
98-
* <p/>
99-
* Reference:
97+
* Request to generates audio from the input text. Reference:
10098
* <a href="https://platform.openai.com/docs/api-reference/audio/createSpeech">Create
10199
* Speech</a>
102100
*
@@ -116,7 +114,7 @@ public record SpeechRequest(
116114
@JsonProperty("model") String model,
117115
@JsonProperty("input") String input,
118116
@JsonProperty("voice") Voice voice,
119-
@JsonProperty("response_format") AudioResponseFormat response_format,
117+
@JsonProperty("response_format") AudioResponseFormat responseFormat,
120118
@JsonProperty("speed") Float speed) {
121119
// @formatter:on
122120

@@ -281,9 +279,9 @@ public record TranscriptionRequest(
281279
@JsonProperty("model") String model,
282280
@JsonProperty("language") String language,
283281
@JsonProperty("prompt") String prompt,
284-
@JsonProperty("response_format") TextualResponseFormat response_format,
282+
@JsonProperty("response_format") TextualResponseFormat responseFormat,
285283
@JsonProperty("temperature") Float temperature,
286-
@JsonProperty("timestamp_granularities") GranularityType timestampGranularities) {
284+
@JsonProperty("timestamp_granularities") GranularityType granularityType) {
287285
// @formatter:on
288286

289287
public enum GranularityType {
@@ -563,37 +561,19 @@ public record Segment(
563561
/**
564562
* Request to generates audio from the input text.
565563
* @param requestBody The request body.
566-
* @return The audio file in bytes. You can use the
567-
* {@link #saveToFile(byte[], String)} to save the audio to a file.
564+
* @return The audio file in bytes.
568565
*/
569566
public byte[] createSpeech(SpeechRequest requestBody) {
570567
return this.restClient.post().uri("/v1/audio/speech").body(requestBody).retrieve().body(byte[].class);
571568
}
572569

573-
// /**
574-
// * Saves the audio binary into a file.
575-
// * @param audioContent The audio as byte array.
576-
// * @param fileName The file name to save the audio to.
577-
// */
578-
// public static void saveToFile(byte[] audioContent, String fileName) {
579-
580-
// try {
581-
// var fos = new FileOutputStream(fileName);
582-
// StreamUtils.copy(audioContent, fos);
583-
// fos.close();
584-
// }
585-
// catch (Exception e) {
586-
// throw new RuntimeException(e);
587-
// }
588-
// };
589-
590570
/**
591571
* Transcribes audio into the input language.
592572
* @param requestBody The request body.
593573
* @return The transcribed text.
594574
*/
595575
public Object createTranscription(TranscriptionRequest requestBody) {
596-
return createTranscription(requestBody, requestBody.response_format().getResponseType());
576+
return createTranscription(requestBody, requestBody.responseFormat().getResponseType());
597577
}
598578

599579
/**
@@ -616,12 +596,12 @@ public String getFilename() {
616596
multipartBody.add("model", requestBody.model());
617597
multipartBody.add("language", requestBody.language());
618598
multipartBody.add("prompt", requestBody.prompt());
619-
multipartBody.add("response_format", requestBody.response_format().getValue());
599+
multipartBody.add("response_format", requestBody.responseFormat().getValue());
620600
multipartBody.add("temperature", requestBody.temperature());
621-
if (requestBody.timestampGranularities() != null) {
622-
Assert.isTrue(requestBody.response_format() == TextualResponseFormat.VERBOSE_JSON,
601+
if (requestBody.granularityType() != null) {
602+
Assert.isTrue(requestBody.responseFormat() == TextualResponseFormat.VERBOSE_JSON,
623603
"response_format must be set to verbose_json to use timestamp granularities.");
624-
multipartBody.add("timestamp_granularities[]", requestBody.timestampGranularities().getValue());
604+
multipartBody.add("timestamp_granularities[]", requestBody.granularityType().getValue());
625605
}
626606

627607
return this.restClient.post().uri("/v1/audio/transcriptions").body(multipartBody).retrieve().body(responseType);

0 commit comments

Comments
 (0)