@@ -94,9 +94,7 @@ public String getValue() {
94
94
}
95
95
96
96
/**
97
- * Request to generates audio from the input text.
98
- * <p/>
99
- * Reference:
97
+ * Request to generates audio from the input text. Reference:
100
98
* <a href="https://platform.openai.com/docs/api-reference/audio/createSpeech">Create
101
99
* Speech</a>
102
100
*
@@ -116,7 +114,7 @@ public record SpeechRequest(
116
114
@ JsonProperty ("model" ) String model ,
117
115
@ JsonProperty ("input" ) String input ,
118
116
@ JsonProperty ("voice" ) Voice voice ,
119
- @ JsonProperty ("response_format" ) AudioResponseFormat response_format ,
117
+ @ JsonProperty ("response_format" ) AudioResponseFormat responseFormat ,
120
118
@ JsonProperty ("speed" ) Float speed ) {
121
119
// @formatter:on
122
120
@@ -281,9 +279,9 @@ public record TranscriptionRequest(
281
279
@ JsonProperty ("model" ) String model ,
282
280
@ JsonProperty ("language" ) String language ,
283
281
@ JsonProperty ("prompt" ) String prompt ,
284
- @ JsonProperty ("response_format" ) TextualResponseFormat response_format ,
282
+ @ JsonProperty ("response_format" ) TextualResponseFormat responseFormat ,
285
283
@ JsonProperty ("temperature" ) Float temperature ,
286
- @ JsonProperty ("timestamp_granularities" ) GranularityType timestampGranularities ) {
284
+ @ JsonProperty ("timestamp_granularities" ) GranularityType granularityType ) {
287
285
// @formatter:on
288
286
289
287
public enum GranularityType {
@@ -563,37 +561,19 @@ public record Segment(
563
561
/**
564
562
* Request to generates audio from the input text.
565
563
* @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.
568
565
*/
569
566
public byte [] createSpeech (SpeechRequest requestBody ) {
570
567
return this .restClient .post ().uri ("/v1/audio/speech" ).body (requestBody ).retrieve ().body (byte [].class );
571
568
}
572
569
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
-
590
570
/**
591
571
* Transcribes audio into the input language.
592
572
* @param requestBody The request body.
593
573
* @return The transcribed text.
594
574
*/
595
575
public Object createTranscription (TranscriptionRequest requestBody ) {
596
- return createTranscription (requestBody , requestBody .response_format ().getResponseType ());
576
+ return createTranscription (requestBody , requestBody .responseFormat ().getResponseType ());
597
577
}
598
578
599
579
/**
@@ -616,12 +596,12 @@ public String getFilename() {
616
596
multipartBody .add ("model" , requestBody .model ());
617
597
multipartBody .add ("language" , requestBody .language ());
618
598
multipartBody .add ("prompt" , requestBody .prompt ());
619
- multipartBody .add ("response_format" , requestBody .response_format ().getValue ());
599
+ multipartBody .add ("response_format" , requestBody .responseFormat ().getValue ());
620
600
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 ,
623
603
"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 ());
625
605
}
626
606
627
607
return this .restClient .post ().uri ("/v1/audio/transcriptions" ).body (multipartBody ).retrieve ().body (responseType );
0 commit comments