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();
}
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();
}
Aggregations