if (LOGGER.isLoggable(Level.FINE)) {
LOGGER.fine("=== " +
utterance.getString("input_text"));
}
AudioPlayer audioPlayer = utterance.getVoice().getAudioPlayer();
audioPlayer.setAudioFormat(MBROLA_AUDIO);
audioPlayer.setVolume(utterance.getVoice().getVolume());
// The AudioPlayer interface currently does not allow streaming audio.
// We need to know the total number of samples that will be written
// before we can start writing them. Therefore, we need to load all
// audio data for this utterance into RAM.
List audioData = (List) utterance.getObject("mbrolaAudio");
if (audioData == null) {
throw new ProcessException
("No \"mbrolaAudio\" object is associated with utterance");
}
// total number of audio bytes
int totalSize;
try {
totalSize = utterance.getInt("mbrolaAudioLength");
} catch (NullPointerException npe) {
totalSize = 0;
}
audioPlayer.begin(totalSize);
for (Iterator it = audioData.iterator(); it.hasNext();) {
byte[] bytes = (byte[]) it.next();
if (!audioPlayer.write(bytes)) {
throw new ProcessException
("Cannot write audio data to audio player");
}
}
if (!audioPlayer.end()) {
throw new ProcessException("audio player reports problem");
}
}