I have been working on PocketSphinx Android voice command project where the user can open application listed on their Android by use command "open xxx" (I made "open" as Keyword and xxx is application's name), but sadly it didn't work.
My question is, how PocketSphinx recognize two-words command, where the first word is Keyword and the second word is a dynamic word (user can say any application's name).
Declare keyword:
public class PocketSphinxActivity extends Activity implements
RecognitionListener {
/* Named searches allow to quickly reconfigure the decoder */
private static final String KWS_SEARCH = "wakeup";
/* Keyword we are looking for to activate menu */
private static final String KEYPHRASE = "open";
I tried to Split() two-words keyword (ex: open camera) and successfully opened camera, but what I need is "open xxx" so the user can define any application they want. That's why I change keyword to "open" only.
public void onPartialResult(Hypothesis hypothesis) {
if (hypothesis == null)
return;
String text = hypothesis.getHypstr();
String[] split = text.split("\\s+");
String word1 = split[0];
String word2 = split[1];
if (word2 != null) {
if (word1.equals("open")) {
PackageManager packageManager = getPackageManager();
List<PackageInfo> packs = packageManager.getInstalledPackages(0);
int size = packs.size();
boolean uninstallApp = false;
boolean exceptFlg = false;
for (int v = 0; v < size; v++) {
PackageInfo p = packs.get(v);
String tmpAppName = p.applicationInfo.loadLabel(packageManager).toString();
String pname = p.packageName;
tmpAppName = tmpAppName.toLowerCase();
if (tmpAppName.trim().toLowerCase().equals(word2.trim().toLowerCase())) {
PackageManager pm = this.getPackageManager();
Intent appStartIntent = pm.getLaunchIntentForPackage(pname);
if (null != appStartIntent) {
try {
this.startActivity(appStartIntent);
} catch (Exception e) {
}
}
}
}
finish();
public void onResult(Hypothesis hypothesis) {
((TextView) findViewById(R.id.result_text)).setText("");
if (hypothesis != null) {
String text = hypothesis.getHypstr();
String[] split = text.split("\\s+");
String word1 = split[0];
String word2 = split[1];
makeText(getApplicationContext(), text, Toast.LENGTH_SHORT).show();
}
}
Any help on this would be grateful. I really need it to complete my final project. Thank you.