Java Google Text to Speech: воспроизведение ответа, не конвертирование в mp3JAVA

Программисты JAVA общаются здесь
Anonymous
Java Google Text to Speech: воспроизведение ответа, не конвертирование в mp3

Сообщение Anonymous »

Я использую API преобразования текста в речь Google и пытаюсь понять, как можно сразу воспроизвести ответ Google, а не преобразовывать его в mp3-файл

Код: Выделить всё

 public static void TTS(String word) throws IOException {
authExplicit();
try (

// Set the text input to be synthesized
SynthesisInput input = SynthesisInput.newBuilder().setText(word).build();

// Build the voice request, select the language code ("en-US") and the ssml voice gender
// ("neutral")
VoiceSelectionParams voice =
VoiceSelectionParams.newBuilder()
.setLanguageCode("en-US")
.setSsmlGender(SsmlVoiceGender.NEUTRAL)
.build();

// Select the type of audio file you want returned
AudioConfig audioConfig =
AudioConfig.newBuilder().setAudioEncoding(AudioEncoding.MP3).build();

// Perform the text-to-speech request on the text input with the selected voice parameters and
// audio file type
SynthesizeSpeechResponse response =
textToSpeechClient.synthesizeSpeech(input, voice, audioConfig);

// Get the audio contents from the response
ByteString audioContents = response.getAudioContent();

// HERE, I DO NOT WANT TO CONVERT TO MP3. I just want the audio played out.....
try (OutputStream out = new FileOutputStream("output.mp3")) {
out.write(audioContents.toByteArray());

System.out.println("Audio content written to file \"output.mp3\"");
}

}
}

Вернуться в «JAVA»