use of ai.saiy.android.user.SaiyAccountList in project Saiy-PS by brandall76.
the class CommandVocalRecognition method getResponse.
/**
* Resolve the required command returning an {@link Outcome} object
*
* @param ctx the application context
* @param sl the {@link SupportedLanguage} we are using to analyse the voice data.
* @return {@link Outcome} containing everything we need to respond to the command.
*/
public Outcome getResponse(@NonNull final Context ctx, @NonNull final SupportedLanguage sl) {
final long then = System.nanoTime();
final Outcome outcome = new Outcome();
outcome.setQubit(new Qubit());
final SaiyAccountList saiyAccountList = SaiyAccountHelper.getAccounts(ctx);
if (saiyAccountList != null && saiyAccountList.size() > 0) {
if (DEBUG) {
MyLog.v(CLS_NAME, "saiyAccountList.size: " + saiyAccountList.size());
}
switch(saiyAccountList.size()) {
case 1:
default:
final SaiyAccount saiyAccount = saiyAccountList.getSaiyAccountList().get(0);
if (saiyAccount != null) {
final ProfileItem profileItem = saiyAccount.getProfileItem();
if (profileItem != null) {
final String profileId = profileItem.getId();
if (UtilsString.notNaked(profileId)) {
if (DEBUG) {
MyLog.d(CLS_NAME, "profileId: " + profileId);
}
final Speaker.Status status = Speaker.Status.getStatus(profileItem.getStatus());
if (DEBUG) {
MyLog.d(CLS_NAME, "status: " + status.name());
}
switch(status) {
case SUCCEEDED:
outcome.setUtterance(SaiyResourcesHelper.getStringResource(ctx, sl, R.string.speech_enroll_instructions_15));
outcome.setAction(LocalRequest.ACTION_SPEAK_LISTEN);
outcome.setOutcome(Outcome.SUCCESS);
outcome.setExtra(profileId);
break;
default:
if (DEBUG) {
MyLog.w(CLS_NAME, "enrollment status");
}
outcome.setOutcome(Outcome.FAILURE);
outcome.setUtterance(SaiyResourcesHelper.getStringResource(ctx, sl, R.string.error_vi_status));
break;
}
} else {
if (DEBUG) {
MyLog.w(CLS_NAME, "profile id naked");
}
outcome.setOutcome(Outcome.FAILURE);
outcome.setUtterance(SaiyResourcesHelper.getStringResource(ctx, sl, R.string.error_vi_status));
}
} else {
if (DEBUG) {
MyLog.w(CLS_NAME, "profile item null");
}
outcome.setOutcome(Outcome.FAILURE);
outcome.setUtterance(SaiyResourcesHelper.getStringResource(ctx, sl, R.string.error_vi_status));
}
} else {
if (DEBUG) {
MyLog.w(CLS_NAME, "account null");
}
outcome.setOutcome(Outcome.FAILURE);
outcome.setUtterance(SaiyResourcesHelper.getStringResource(ctx, sl, R.string.error_vi_no_account));
}
break;
}
} else {
if (DEBUG) {
MyLog.w(CLS_NAME, "no accounts");
}
outcome.setOutcome(Outcome.FAILURE);
outcome.setUtterance(SaiyResourcesHelper.getStringResource(ctx, sl, R.string.error_vi_no_account));
}
if (DEBUG) {
MyLog.getElapsed(CLS_NAME, then);
}
return outcome;
}
Aggregations