-
Notifications
You must be signed in to change notification settings - Fork 197
Open
Labels
Description
Hi there, how to save the response data to a audio file when setting stream_format=sse, my code as below, the audio file can't be played.
And what's the meaning of stream_format=sse, does it like the steaming response with chat completion api ?
static void speech() throws IOException {
SpeechCreateParams createParams = SpeechCreateParams.builder()
.model(SpeechModel.GPT_4O_MINI_TTS)
.input("金十数据12月31日讯,商务部新闻发言人就荷兰经济大臣卡雷曼斯接受采访答记者问表示,中方已多次强调,荷方对安世半导体企业内部事务的不当行政干预,已导致全球半导体供应链危机,荷方必须对此承担全部责任。")
.responseFormat(SpeechCreateParams.ResponseFormat.WAV)
.streamFormat(SpeechCreateParams.StreamFormat.SSE)
.voice(SpeechCreateParams.Voice.ALLOY)
.build();
InputStream inputStream = buildClient().audio()
.withRawResponse()
.speech()
.create(createParams)
.body();
Path tempDir = Path.of("temp");
Files.createDirectories(tempDir);
Path outputFile = tempDir.resolve(System.currentTimeMillis() + ".wav");
Files.copy(inputStream, outputFile, StandardCopyOption.REPLACE_EXISTING);
}