Search in sources :

Example 1 with PostContentResult

use of com.amazonaws.services.lexrts.model.PostContentResult in project aws-sdk-android by aws-amplify.

the class InteractionClient method carryOnWithText.

/**
 * Accepts user's response as {@link String}.
 */
private void carryOnWithText(final String text, final Map<String, String> sessionAttributes, final Map<String, String> requestAttributes, final ResponseType mode) {
    // Ensure the client is not pre-occupied with a request.
    checkBusyState();
    // Send user's response to Amazon Lex service as a text.
    final InteractionClient client = this;
    new Thread(new Runnable() {

        @Override
        public void run() {
            final Handler handler = new Handler(context.getMainLooper());
            Runnable returnCallback;
            try {
                final PostContentRequest request = CreateLexServiceRequest.generatePostContentRequest(sessionAttributes, requestAttributes, interactionConfig, credentialsProvider, mode, text);
                final PostContentResult result = amazonlex.postContent(request);
                processResponseAudioPlayback(handler, result, client, mode, ResponseType.TEXT);
            } catch (final Exception e) {
                returnCallback = new Runnable() {

                    @Override
                    public void run() {
                        interactionListener.onInteractionError(null, e);
                    }
                };
                handler.post(returnCallback);
            } finally {
                setBusyState(NOT_BUSY);
            }
        }
    }).start();
}
Also used : PostContentRequest(com.amazonaws.services.lexrts.model.PostContentRequest) Handler(android.os.Handler) PostContentResult(com.amazonaws.services.lexrts.model.PostContentResult) InvalidParameterException(com.amazonaws.mobileconnectors.lex.interactionkit.exceptions.InvalidParameterException) LexClientException(com.amazonaws.mobileconnectors.lex.interactionkit.exceptions.LexClientException) MaxSpeechTimeOutException(com.amazonaws.mobileconnectors.lex.interactionkit.exceptions.MaxSpeechTimeOutException) DialogFailedException(com.amazonaws.mobileconnectors.lex.interactionkit.exceptions.DialogFailedException) NoSpeechTimeOutException(com.amazonaws.mobileconnectors.lex.interactionkit.exceptions.NoSpeechTimeOutException) AmazonClientException(com.amazonaws.AmazonClientException) AudioPlaybackException(com.amazonaws.mobileconnectors.lex.interactionkit.exceptions.AudioPlaybackException)

Example 2 with PostContentResult

use of com.amazonaws.services.lexrts.model.PostContentResult in project aws-sdk-android by aws-amplify.

the class InteractionClient method sendAudioRequest.

/**
 * This method will be invoked when speech frames are detected in the audio
 * input over the microphone.
 *
 * @param handler {@link Handler}, to interact with app components in the
 *                main thread.
 * @param request {@link PostContentResult}, response from the Amazon Lex
 *                service.
 * @param client  {@link InteractionClient}, reference to this object.
 * @param mode    {@link ResponseType}, current response type.
 */
private void sendAudioRequest(final Handler handler, final PostContentRequest request, final InteractionClient client, final ResponseType mode) {
    new Thread(new Runnable() {

        @Override
        public void run() {
            try {
                final PostContentResult result = amazonlex.postContent(request);
                processResponseAudioPlayback(handler, result, client, mode, ResponseType.AUDIO_MPEG);
            } catch (final Exception e) {
                final Runnable returnCallBack = new Runnable() {

                    @Override
                    public void run() {
                        interactionListener.onInteractionError(null, e);
                    }
                };
                handler.post(returnCallBack);
            } finally {
                setBusyState(NOT_BUSY);
            }
        }
    }).start();
}
Also used : PostContentResult(com.amazonaws.services.lexrts.model.PostContentResult) InvalidParameterException(com.amazonaws.mobileconnectors.lex.interactionkit.exceptions.InvalidParameterException) LexClientException(com.amazonaws.mobileconnectors.lex.interactionkit.exceptions.LexClientException) MaxSpeechTimeOutException(com.amazonaws.mobileconnectors.lex.interactionkit.exceptions.MaxSpeechTimeOutException) DialogFailedException(com.amazonaws.mobileconnectors.lex.interactionkit.exceptions.DialogFailedException) NoSpeechTimeOutException(com.amazonaws.mobileconnectors.lex.interactionkit.exceptions.NoSpeechTimeOutException) AmazonClientException(com.amazonaws.AmazonClientException) AudioPlaybackException(com.amazonaws.mobileconnectors.lex.interactionkit.exceptions.AudioPlaybackException)

Aggregations

AmazonClientException (com.amazonaws.AmazonClientException)2 AudioPlaybackException (com.amazonaws.mobileconnectors.lex.interactionkit.exceptions.AudioPlaybackException)2 DialogFailedException (com.amazonaws.mobileconnectors.lex.interactionkit.exceptions.DialogFailedException)2 InvalidParameterException (com.amazonaws.mobileconnectors.lex.interactionkit.exceptions.InvalidParameterException)2 LexClientException (com.amazonaws.mobileconnectors.lex.interactionkit.exceptions.LexClientException)2 MaxSpeechTimeOutException (com.amazonaws.mobileconnectors.lex.interactionkit.exceptions.MaxSpeechTimeOutException)2 NoSpeechTimeOutException (com.amazonaws.mobileconnectors.lex.interactionkit.exceptions.NoSpeechTimeOutException)2 PostContentResult (com.amazonaws.services.lexrts.model.PostContentResult)2 Handler (android.os.Handler)1 PostContentRequest (com.amazonaws.services.lexrts.model.PostContentRequest)1