use of ai.saiy.android.api.request.SaiyKeyphrase in project API-Example-App by brandall76.
the class FragmentDemoCommand method registerKeyphrase.
/**
* Handle the button click and register the corresponding keyphrase
*
* @param id of the view that was clicked
*/
@SuppressWarnings("ConstantConditions")
public void registerKeyphrase(final int id) {
Log.i(CLS_NAME, "registerKeyphrase");
if (MainActivity.saiyAvailable) {
final SaiyKeyphrase keyphraseRequest = new SaiyKeyphrase(getActivity().getApplicationContext(), this);
switch(id) {
case R.id.buttonC1:
keyphraseRequest.setDefinedAction(DO_SOMETHING_1);
keyphraseRequest.setSaiyKeyphrase(SAUSAGES);
keyphraseRequest.setRegex(Regex.MATCHES);
break;
case R.id.buttonC2:
keyphraseRequest.setDefinedAction(DO_SOMETHING_2);
keyphraseRequest.setSaiyKeyphrase(SPOTIFY_PLAYLIST);
keyphraseRequest.setRegex(Regex.STARTS_WITH);
break;
case R.id.buttonC3:
keyphraseRequest.setDefinedAction(DO_SOMETHING_3);
keyphraseRequest.setSaiyKeyphrase(SPOTIFY_ALBUM);
keyphraseRequest.setRegex(Regex.STARTS_WITH);
break;
}
/*
* When registering a keyphrase, you can include a bundle containing
* any type of parameter. When the keyphrase is detected, a bundle will
* be returned containing these original parameters, which can be used
* to handle the action you intend to make.
*/
final Bundle bundle = new Bundle();
bundle.putString("some bundle String", "random String value");
bundle.putBoolean("some bundle boolean", true);
bundle.putInt("some bundle int", Integer.MAX_VALUE);
keyphraseRequest.setExtraBundle(bundle);
/*
* In production, you would identify the keyphrase detected by the
* constant set here.
*/
final int myUniqueId;
switch(id) {
case R.id.buttonC1:
myUniqueId = KEYPHRASE_ID_1;
break;
case R.id.buttonC2:
myUniqueId = KEYPHRASE_ID_2;
break;
case R.id.buttonC3:
myUniqueId = KEYPHRASE_ID_3;
break;
default:
myUniqueId = 666;
break;
}
final boolean interimSuccess = keyphraseRequest.sendRequest(myUniqueId);
if (interimSuccess) {
Log.i(CLS_NAME, "The keyphrase request initially returned: true from the library ~ However, " + "if the request fails to work, please view the logcat for " + "information, as on receipt of the request, Saiy will perform more stringent tests which " + "are subject to change. The final outcome will be received in onEnrollKeyphrase");
} else {
Log.e(CLS_NAME, "The keyphrase request was declined. Check the logcat for more information");
}
} else {
Log.w(CLS_NAME, "Saiy is unavailable. Please check the log for more information");
}
}
Aggregations