private void handle()

in src/main/java/com/amazonaws/lex/twilio/sample/streaming/BotResponseHandler.java [145:171]


    private void handle(AudioResponseEvent event) {//synthesize speech
        // LOG.info("Got a AudioResponseEvent: " + event);
        if (audioResponse == null && event.audioChunk() != null) {

            LOG.info("got a non empty audio response. starting a audio response collector in a separate thread");
            audioResponse = new AudioResponse();
            CompletableFuture.runAsync(() -> twilioCallOperator.playback(audioResponse)).whenComplete((result, error) -> {
                if (error != null) {
                    error.printStackTrace();
                }
            });
        }

        if (event.audioChunk() != null) {
            audioResponse.write(event.audioChunk().asByteArray());
        } else {
            // no audio bytes means audio prompt has ended.
            try {
                if (audioResponse != null) {
                    audioResponse.close();
                }
                audioResponse = null;  // prepare  for next audio prompt.
            } catch (IOException e) {
                throw new UncheckedIOException("got an exception when closing the audio response", e);
            }
        }
    }