use of ai.saiy.android.service.helper.LocalRequest in project Saiy-PS by brandall76.
the class ActivityHome method speak.
/**
* Utility method to vocalise any UI content or descriptions
*
* @param utterance to the String to speak
* @param action one of {@link LocalRequest#ACTION_SPEAK_ONLY} {@link LocalRequest#ACTION_SPEAK_LISTEN}
*/
public void speak(@NonNull final String utterance, final int action) {
new Thread(new Runnable() {
@Override
public void run() {
final LocalRequest request = new LocalRequest(ActivityHome.this.getApplicationContext());
request.prepareDefault(action, utterance);
request.execute();
}
}).start();
}
use of ai.saiy.android.service.helper.LocalRequest in project Saiy-PS by brandall76.
the class GoogleNowMonitor method restartHotword.
/**
* Send a request to restart the hotword detection
*
* @param ctx the application context
*/
private void restartHotword(@NonNull final Context ctx) {
if (DEBUG) {
MyLog.i(CLS_NAME, "restartHotword");
}
final LocalRequest request = new LocalRequest(ctx);
request.prepareDefault(LocalRequest.ACTION_START_HOTWORD, null);
request.execute();
}
use of ai.saiy.android.service.helper.LocalRequest in project Saiy-PS by brandall76.
the class BRBoot method onReceive.
@Override
public void onReceive(final Context context, final Intent intent) {
if (DEBUG) {
MyLog.i(CLS_NAME, "onReceive");
}
if (SPH.getSelfAwareEnabled(context.getApplicationContext()) && SPH.getStartAtBoot(context.getApplicationContext())) {
final String action = getAction(intent);
if (UtilsString.notNaked(action) && action.equals(Intent.ACTION_BOOT_COMPLETED) || action.equals("android.intent.action.QUICKBOOT_POWERON") || action.equals("com.htc.intent.action.QUICKBOOT_POWERON")) {
if (DEBUG) {
MyLog.i(CLS_NAME, "onReceive: starting service");
}
SelfAwareHelper.startSelfAwareIfRequired(context.getApplicationContext());
if (SPH.getHotwordBoot(context.getApplicationContext())) {
final LocalRequest request = new LocalRequest(context.getApplicationContext());
request.prepareDefault(LocalRequest.ACTION_START_HOTWORD, null);
request.execute();
} else {
if (DEBUG) {
MyLog.i(CLS_NAME, "onReceive: start at boot hotword disabled by user");
}
}
} else {
if (DEBUG) {
MyLog.w(CLS_NAME, "onReceive: action naked or unknown");
}
}
} else {
if (DEBUG) {
MyLog.i(CLS_NAME, "onReceive: start at boot disabled by user");
}
}
}
use of ai.saiy.android.service.helper.LocalRequest in project Saiy-PS by brandall76.
the class BRRemote method onReceive.
@Override
public void onReceive(final Context context, final Intent intent) {
if (DEBUG) {
MyLog.i(CLS_NAME, "onReceive");
}
if (intent == null) {
if (DEBUG) {
MyLog.w(CLS_NAME, " onHandleIntent: Intent null");
}
return;
}
final String action = intent.getAction();
if (DEBUG) {
examineIntent(intent);
}
if (!UtilsString.notNaked(action)) {
if (DEBUG) {
MyLog.w(CLS_NAME, " onHandleIntent: action null");
}
return;
}
if (!intent.getAction().equals(SaiyKeyphrase.SAIY_REQUEST_RECEIVER)) {
Log.e("Saiy Remote Request", "Incorrect ACTION: rejecting");
return;
}
switch(intent.getIntExtra(SaiyKeyphrase.REQUEST_TYPE, 0)) {
case SaiyKeyphrase.REQUEST_KEYPHRASE:
if (DEBUG) {
MyLog.i(CLS_NAME, "onHandleIntent: REQUEST_KEYPHRASE");
}
final String keyphrase = intent.getStringExtra(SaiyKeyphrase.SAIY_KEYPHRASE);
if (UtilsString.notNaked(keyphrase)) {
final String packageName = intent.getStringExtra(SaiyKeyphrase.REQUESTING_PACKAGE);
if (UtilsString.notNaked(packageName)) {
final BlackListHelper blackListHelper = new BlackListHelper();
if (!blackListHelper.isBlacklisted(context, packageName)) {
final Pair<Boolean, String> appPair = UtilsApplication.getAppNameFromPackage(context.getApplicationContext(), packageName);
if (appPair.first && UtilsString.notNaked(appPair.second)) {
final Locale vrLocale = SPH.getVRLocale(context.getApplicationContext());
final SupportedLanguage sl = SupportedLanguage.getSupportedLanguage(vrLocale);
final ArrayList<String> voiceData = new ArrayList<>(1);
voiceData.add(keyphrase);
final float[] confidence = new float[1];
confidence[0] = 1f;
final ArrayList<Pair<CC, Float>> resolvePair = new Resolve(context.getApplicationContext(), voiceData, confidence, sl).resolve();
if (!UtilsList.notNaked(resolvePair)) {
final CustomCommand customCommand = new CustomCommand(CCC.CUSTOM_INTENT_SERVICE, CC.COMMAND_USER_CUSTOM, keyphrase, SaiyRequestParams.SILENCE, SaiyRequestParams.SILENCE, SPH.getTTSLocale(context.getApplicationContext()).toString(), vrLocale.toString(), LocalRequest.ACTION_SPEAK_ONLY);
final Regex regex = (Regex) intent.getSerializableExtra(SaiyKeyphrase.KEYPHRASE_REGEX);
switch(regex) {
case MATCHES:
case STARTS_WITH:
case ENDS_WITH:
case CONTAINS:
customCommand.setRegex(regex);
break;
case CUSTOM:
customCommand.setRegex(regex);
customCommand.setRegularExpression(intent.getStringExtra(SaiyKeyphrase.REGEX_CONTENT));
break;
}
final Intent remoteIntent = new Intent(SAIY_INTENT_RECEIVER);
remoteIntent.setPackage(packageName);
final Bundle bundle = intent.getExtras();
if (UtilsBundle.notNaked(bundle)) {
if (!UtilsBundle.isSuspicious(bundle)) {
if (DEBUG) {
examineIntent(intent);
}
remoteIntent.putExtras(bundle);
customCommand.setIntent(remoteIntent.toUri(0));
final Pair<Boolean, Long> successPair = CustomCommandHelper.setCommand(context.getApplicationContext(), customCommand, -1);
if (DEBUG) {
MyLog.i(CLS_NAME, "Custom command created: " + successPair.first);
}
final Bundle responseBundle = new Bundle();
final int responseCode = bundle.getInt(SaiyKeyphrase.SAIY_KEYPHRASE_ID, 0);
if (DEBUG) {
MyLog.i(CLS_NAME, "Custom command responseCode: " + responseCode);
}
responseBundle.putInt(SaiyKeyphrase.SAIY_KEYPHRASE_ID, responseCode);
final LocalRequest request = new LocalRequest(context.getApplicationContext());
request.setVRLocale(vrLocale);
request.setTTSLocale(SPH.getTTSLocale(context.getApplicationContext()));
request.setSupportedLanguage(sl);
request.setQueueType(SaiyTextToSpeech.QUEUE_ADD);
request.setAction(LocalRequest.ACTION_SPEAK_ONLY);
if (successPair.first) {
request.setUtterance(PersonalityResponse.getRemoteCommandRegisterSuccess(context.getApplicationContext(), sl, appPair.second, keyphrase));
request.execute();
setResult(Activity.RESULT_OK, SaiyKeyphrase.class.getSimpleName(), responseBundle);
} else {
request.setUtterance(PersonalityResponse.getErrorRemoteCommandRegister(context.getApplicationContext(), sl, appPair.second));
request.execute();
setResult(Activity.RESULT_CANCELED, SaiyKeyphrase.class.getSimpleName(), responseBundle);
}
} else {
Log.e("Saiy Remote Request", "Bundle rejected due to contents");
}
} else {
Log.e("Saiy Remote Request", "Request bundle missing contents: rejected");
}
} else {
Log.e("Saiy Remote Request", "Conflict with inbuilt command: rejected");
}
} else {
Log.e("Saiy Remote Request", "Application name undetectable: rejected");
}
} else {
Log.e("Saiy Remote Request", "Application blacklisted: rejected");
}
} else {
Log.e("Saiy Remote Request", "Package name missing: rejected");
}
} else {
Log.e("Saiy Remote Request", "Keyphrase missing: rejected");
}
break;
default:
Log.e("Saiy Remote Request", "Internal type error: rejected");
break;
}
}
use of ai.saiy.android.service.helper.LocalRequest in project Saiy-PS by brandall76.
the class BVStreamAudio method proceedAndNotify.
private void proceedAndNotify() {
if (retryCount < 2) {
if (retryCount == 0) {
final LocalRequest localRequest = new LocalRequest(mic.getContext());
localRequest.setSupportedLanguage(sl);
localRequest.setAction(LocalRequest.ACTION_SPEAK_ONLY);
localRequest.setTTSLocale(SPH.getTTSLocale(mic.getContext()));
localRequest.setVRLocale(SPH.getVRLocale(mic.getContext()));
localRequest.setUtterance(PersonalityResponse.getBVAnalysisCompleteResponse(mic.getContext(), sl));
localRequest.execute();
}
retryCount++;
final TimerTask timerTask = new TimerTask() {
@Override
public void run() {
if (DEBUG) {
MyLog.i(CLS_NAME, "timerTask: fetching analysis");
}
if (!new BVEmotionAnalysis(mic.getContext(), sl, token).getAnalysis(recordingId, 0).first) {
proceedAndNotify();
}
}
};
new Timer().schedule(timerTask, BeyondVerbal.FETCH_ANALYSIS_DELAY);
}
}
Aggregations