Search in sources :

Example 1 with SupportedLanguage

use of ai.saiy.android.localisation.SupportedLanguage in project Saiy-PS by brandall76.

the class FragmentSuperuserHelper method enrollmentFailed.

/**
 * Notify the user that the account creation failed
 *
 * @param accountName the account name
 */
private void enrollmentFailed(@NonNull final String accountName) {
    if (DEBUG) {
        MyLog.i(CLS_NAME, "enrollmentFailed");
    }
    final SupportedLanguage sl = SupportedLanguage.getSupportedLanguage(SPH.getVRLocale(getApplicationContext()));
    getParentActivity().speak(PersonalityResponse.getEnrollmentAPIError(getApplicationContext(), sl), LocalRequest.ACTION_SPEAK_ONLY);
    SaiyAccountHelper.deleteAccount(getApplicationContext(), accountName, null);
}
Also used : SupportedLanguage(ai.saiy.android.localisation.SupportedLanguage)

Example 2 with SupportedLanguage

use of ai.saiy.android.localisation.SupportedLanguage in project Saiy-PS by brandall76.

the class CustomCommandHelper method commandExists.

/**
 * Check if the keyphrase for the custom command already exists
 *
 * @param dbCustomCommand the {@link DBCustomCommand}
 * @param customCommand   the prepared {@link CustomCommand}
 * @return true if the keyphrase exists, false otherwise
 */
private static Pair<Boolean, Long> commandExists(@NonNull final DBCustomCommand dbCustomCommand, @NonNull final CustomCommand customCommand) {
    if (dbCustomCommand.databaseExists()) {
        final ArrayList<CustomCommandContainer> customCommandContainerArray = dbCustomCommand.getKeyphrases();
        if (UtilsList.notNaked(customCommandContainerArray)) {
            if (DEBUG) {
                MyLog.i(CLS_NAME, "have commands");
            }
            final SupportedLanguage sl = SupportedLanguage.getSupportedLanguage(UtilsLocale.stringToLocale(customCommand.getVRLocale()));
            final Locale loc = sl.getLocale();
            for (final CustomCommandContainer ccc : customCommandContainerArray) {
                if (ccc.getKeyphrase().toLowerCase(loc).trim().matches(customCommand.getKeyphrase().toLowerCase(loc).trim())) {
                    if (DEBUG) {
                        MyLog.i(CLS_NAME, "keyphrase matched: " + ccc.getKeyphrase() + " ~ " + customCommand.getKeyphrase());
                    }
                    return new Pair<>(true, ccc.getRowId());
                }
            }
            if (DEBUG) {
                MyLog.i(CLS_NAME, "command is not a duplicate");
            }
        } else {
            if (DEBUG) {
                MyLog.i(CLS_NAME, "no commands");
            }
        }
    } else {
        if (DEBUG) {
            MyLog.i(CLS_NAME, "databaseExists: false");
        }
    }
    return new Pair<>(false, -1L);
}
Also used : UtilsLocale(ai.saiy.android.utils.UtilsLocale) Locale(java.util.Locale) SupportedLanguage(ai.saiy.android.localisation.SupportedLanguage) Pair(android.util.Pair)

Example 3 with SupportedLanguage

use of ai.saiy.android.localisation.SupportedLanguage in project Saiy-PS by brandall76.

the class AssistantIntentService method onHandleIntent.

@Override
protected void onHandleIntent(final Intent intent) {
    if (DEBUG) {
        MyLog.i(CLS_NAME, "onHandleIntent");
        examineIntent(intent);
    }
    final Bundle actionBundle = new Bundle();
    actionBundle.putInt(LocalRequest.EXTRA_ACTION, LocalRequest.ACTION_SPEAK_LISTEN);
    if (intent != null) {
        final Bundle bundle = intent.getExtras();
        if (bundle != null) {
            final String action = intent.getAction();
            if (UtilsString.notNaked(action)) {
                if (DEBUG) {
                    MyLog.i(CLS_NAME, "onHandleIntent: action: " + action);
                }
                if (intent.getAction().equals(Intent.ACTION_ASSIST)) {
                    if (DEBUG) {
                        if (bundle.containsKey(EXTRA_ASSIST_CONTEXT)) {
                            final Bundle assistBundle = bundle.getBundle(EXTRA_ASSIST_CONTEXT);
                            MyLog.i(CLS_NAME, "onHandleIntent checking assistBundle");
                            examineBundle(assistBundle);
                        }
                    }
                }
            }
            if (bundle.containsKey(LocalRequest.EXTRA_RECOGNITION_LANGUAGE)) {
                final String vrLocale = bundle.getString(LocalRequest.EXTRA_RECOGNITION_LANGUAGE);
                if (UtilsString.notNaked(vrLocale)) {
                    if (DEBUG) {
                        MyLog.i(CLS_NAME, "onHandleIntent: EXTRA_RECOGNITION_LANGUAGE: " + vrLocale);
                    }
                    actionBundle.putString(LocalRequest.EXTRA_RECOGNITION_LANGUAGE, vrLocale);
                } else {
                    if (DEBUG) {
                        MyLog.i(CLS_NAME, "onHandleIntent: EXTRA_RECOGNITION_LANGUAGE naked");
                    }
                }
            } else {
                if (DEBUG) {
                    MyLog.i(CLS_NAME, "onHandleIntent: no EXTRA_RECOGNITION_LANGUAGE");
                }
            }
            if (bundle.containsKey(LocalRequest.EXTRA_TTS_LANGUAGE)) {
                final String ttsLocale = bundle.getString(LocalRequest.EXTRA_TTS_LANGUAGE);
                if (UtilsString.notNaked(ttsLocale)) {
                    if (DEBUG) {
                        MyLog.i(CLS_NAME, "onHandleIntent: EXTRA_TTS_LANGUAGE: " + ttsLocale);
                    }
                    actionBundle.putString(LocalRequest.EXTRA_TTS_LANGUAGE, ttsLocale);
                } else {
                    if (DEBUG) {
                        MyLog.i(CLS_NAME, "onHandleIntent: EXTRA_TTS_LANGUAGE naked");
                    }
                }
            } else {
                if (DEBUG) {
                    MyLog.i(CLS_NAME, "onHandleIntent: no EXTRA_TTS_LANGUAGE");
                }
            }
            if (bundle.containsKey(LocalRequest.EXTRA_SUPPORTED_LANGUAGE)) {
                final SupportedLanguage supportedLanguage = (SupportedLanguage) bundle.getSerializable(LocalRequest.EXTRA_SUPPORTED_LANGUAGE);
                if (supportedLanguage != null) {
                    actionBundle.putSerializable(LocalRequest.EXTRA_SUPPORTED_LANGUAGE, supportedLanguage);
                    actionBundle.putString(LocalRequest.EXTRA_UTTERANCE, PersonalityHelper.getIntro(getApplicationContext(), supportedLanguage));
                } else {
                    if (DEBUG) {
                        MyLog.i(CLS_NAME, "onHandleIntent: EXTRA_SUPPORTED_LANGUAGE null");
                    }
                }
            } else {
                if (DEBUG) {
                    MyLog.i(CLS_NAME, "onHandleIntent: no EXTRA_SUPPORTED_LANGUAGE");
                }
            }
            if (bundle.containsKey(RecognizerIntent.EXTRA_SECURE)) {
                final Object secureObject = bundle.get(RecognizerIntent.EXTRA_SECURE);
                if (secureObject != null) {
                    boolean secure = false;
                    if (secureObject instanceof Boolean) {
                        secure = (boolean) secureObject;
                    } else if (secureObject instanceof String) {
                        secure = Boolean.parseBoolean((String) secureObject);
                    } else {
                        if (DEBUG) {
                            MyLog.i(CLS_NAME, "onHandleIntent: EXTRA_SECURE of unknown type ignoring");
                        }
                    }
                    if (secure) {
                        actionBundle.putInt(LocalRequest.EXTRA_CONDITION, Condition.CONDITION_SECURE);
                    } else {
                        if (DEBUG) {
                            MyLog.i(CLS_NAME, "onHandleIntent: EXTRA_SECURE false ignoring");
                        }
                    }
                } else {
                    if (DEBUG) {
                        MyLog.i(CLS_NAME, "onHandleIntent: secureObject null");
                    }
                }
            } else {
                if (DEBUG) {
                    MyLog.i(CLS_NAME, "onHandleIntent: no EXTRA_SECURE");
                }
            }
        } else {
            if (DEBUG) {
                MyLog.i(CLS_NAME, "onHandleIntent: bundle null ignoring");
            }
        }
    } else {
        if (DEBUG) {
            MyLog.i(CLS_NAME, "onHandleIntent: intent null ignoring");
        }
    }
    if (!actionBundle.containsKey(LocalRequest.EXTRA_RECOGNITION_LANGUAGE)) {
        actionBundle.putString(LocalRequest.EXTRA_RECOGNITION_LANGUAGE, SPH.getVRLocale(getApplicationContext()).toString());
    } else {
        if (DEBUG) {
            MyLog.i(CLS_NAME, "onHandleIntent: actionBundle: auto adding EXTRA_RECOGNITION_LANGUAGE");
        }
    }
    if (!actionBundle.containsKey(LocalRequest.EXTRA_TTS_LANGUAGE)) {
        actionBundle.putString(LocalRequest.EXTRA_TTS_LANGUAGE, SPH.getTTSLocale(getApplicationContext()).toString());
    } else {
        if (DEBUG) {
            MyLog.i(CLS_NAME, "onHandleIntent: actionBundle: auto adding EXTRA_TTS_LANGUAGE");
        }
    }
    if (!actionBundle.containsKey(LocalRequest.EXTRA_SUPPORTED_LANGUAGE)) {
        @SuppressWarnings("ConstantConditions") final SupportedLanguage sl = SupportedLanguage.getSupportedLanguage(UtilsLocale.stringToLocale(actionBundle.getString(LocalRequest.EXTRA_RECOGNITION_LANGUAGE)));
        actionBundle.putSerializable(LocalRequest.EXTRA_SUPPORTED_LANGUAGE, sl);
        actionBundle.putString(LocalRequest.EXTRA_UTTERANCE, PersonalityHelper.getIntro(getApplicationContext(), sl));
    } else {
        if (DEBUG) {
            MyLog.i(CLS_NAME, "onHandleIntent: actionBundle: auto adding EXTRA_SUPPORTED_LANGUAGE");
        }
    }
    new LocalRequest(getApplicationContext(), actionBundle).execute();
}
Also used : SupportedLanguage(ai.saiy.android.localisation.SupportedLanguage) Bundle(android.os.Bundle) UtilsString(ai.saiy.android.utils.UtilsString)

Example 4 with SupportedLanguage

use of ai.saiy.android.localisation.SupportedLanguage in project Saiy-PS by brandall76.

the class LocalRequest method prepareDefault.

/**
 * Utility method to cut down on boiler plate requests
 *
 * @param action    to perform
 * @param utterance to speak
 */
public void prepareDefault(final int action, @Nullable final String utterance) {
    final Locale vrLocale = SPH.getVRLocale(weakContext.get());
    final SupportedLanguage sl = SupportedLanguage.getSupportedLanguage(vrLocale);
    bundle.putInt(LocalRequest.EXTRA_ACTION, action);
    bundle.putString(LocalRequest.EXTRA_UTTERANCE, utterance);
    bundle.putString(LocalRequest.EXTRA_RECOGNITION_LANGUAGE, vrLocale.toString());
    bundle.putString(LocalRequest.EXTRA_TTS_LANGUAGE, SPH.getTTSLocale(weakContext.get()).toString());
    bundle.putSerializable(LocalRequest.EXTRA_SUPPORTED_LANGUAGE, sl);
}
Also used : UtilsLocale(ai.saiy.android.utils.UtilsLocale) Locale(java.util.Locale) SupportedLanguage(ai.saiy.android.localisation.SupportedLanguage)

Example 5 with SupportedLanguage

use of ai.saiy.android.localisation.SupportedLanguage in project Saiy-PS by brandall76.

the class SelfAwareConditions method getSupportedLanguage.

/**
 * Get the supported language of the {@link Locale} which will enable us to apply any resource
 * localisation when resolving a command.
 *
 * @param servingRemote true if the request is remote
 * @return the {@link SupportedLanguage}
 */
public SupportedLanguage getSupportedLanguage(final boolean servingRemote) {
    if (DEBUG) {
        MyLog.i(CLS_NAME, "getSupportedLanguage");
    }
    SupportedLanguage sl = (SupportedLanguage) getBundle().getSerializable(LocalRequest.EXTRA_SUPPORTED_LANGUAGE);
    if (sl != null) {
        return sl;
    } else {
        if (DEBUG) {
            MyLog.i(CLS_NAME, "getSupportedLanguage: adding to bundle");
        }
        sl = SupportedLanguage.getSupportedLanguage(getVRLocale(servingRemote));
        getBundle().putSerializable(LocalRequest.EXTRA_SUPPORTED_LANGUAGE, sl);
        return sl;
    }
}
Also used : SupportedLanguage(ai.saiy.android.localisation.SupportedLanguage)

Aggregations

SupportedLanguage (ai.saiy.android.localisation.SupportedLanguage)12 Locale (java.util.Locale)5 UtilsLocale (ai.saiy.android.utils.UtilsLocale)4 UtilsString (ai.saiy.android.utils.UtilsString)3 Bundle (android.os.Bundle)3 LocalRequest (ai.saiy.android.service.helper.LocalRequest)2 Intent (android.content.Intent)2 Pair (android.util.Pair)2 ArrayList (java.util.ArrayList)2 BlackListHelper (ai.saiy.android.api.helper.BlackListHelper)1 Regex (ai.saiy.android.api.request.Regex)1 SaiyKeyphrase (ai.saiy.android.api.request.SaiyKeyphrase)1 Speaker (ai.saiy.android.cognitive.identity.provider.microsoft.Speaker)1 CC (ai.saiy.android.command.helper.CC)1 CustomCommand (ai.saiy.android.custom.CustomCommand)1 ExecuteIntent (ai.saiy.android.intent.ExecuteIntent)1 Resolve (ai.saiy.android.nlu.local.Resolve)1 UtilsBundle (ai.saiy.android.utils.UtilsBundle)1