I have an Vuzix m300 (Update 1.2) and I am trying to get my app running with voice control. I really couldn't find any code samples specific for the m300 (I think due to it is to new?). The built in Speech Recognizer works fine. But when I try to use it via the android.speech.SpeechRecognizer I get that Recognition isn't Available...
I have tried some code I found on the Internet and although some code that should work on the m100. Nothing worked for me.
Here is my code:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//grant access to internet
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
//set layout
setContentView(R.layout.activity_main);
boolean b = SpeechRecognizer.isRecognitionAvailable(getApplicationContext());
final List<ResolveInfo> services = getApplicationContext().getPackageManager().queryIntentServices(
new Intent(RecognitionService.SERVICE_INTERFACE), 0);
b = isPackageInstalled(this.getApplicationContext(), "com.google.android.googlequicksearchbox");
}
public static boolean isPackageInstalled(@NonNull final Context ctx, @NonNull final String packageName) {
try {
ctx.getApplicationContext().getPackageManager().getApplicationInfo(packageName, 0);
return true;
} catch (final PackageManager.NameNotFoundException e) {
return false;
}
b is always false and the List services is empty... Therefore I would think that there is no SpeechRecongnizer installed on the Vuzix, but there is (The built in from Vuzix?). I am open for any suggestions!
Edit: I have installed the Google Now App and the Google App and now I can start an SpeechRecognizer. But for some Reason the App won't react to my voice. After some time I get an SpeechRecognizer ERROR_SPEECH_TIMEOUT. The same App works fine on my Android Phone, so I think it is something with the Vuzix M300? My code in onCreate:
speechRecognizer = SpeechRecognizer.createSpeechRecognizer(this);
speechRecognizerIntent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
speechRecognizerIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
speechRecognizerIntent.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE, getApplication().getPackageName());
speechRecognizerIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, "de-DE");
speechRecognizer.setRecognitionListener(prepareRegnitionListener());
speechRecognizer.startListening(speechRecognizerIntent);
and the Rest:
private RecognitionListener prepareRegnitionListener() {
// TODO Auto-generated method stub
return new RecognitionListener() {
@Override
public void onRmsChanged(float rmsdB) {
//Didn´t use
}
@Override
public void onResults(Bundle results) {
ArrayList<String> matches = results.getStringArrayList(SpeechRecognizer.RESULTS_RECOGNITION);
Log.d(MainActivity,"Completed speech recognition: Result: " + matches);
String match = matches.get(0);
}
@Override
public void onReadyForSpeech(Bundle params) {
Log.d(MainActivity, "ReadyforSpeech");
}
@Override
public void onPartialResults(Bundle partialResults) {
// Nothing
}
@Override
public void onEvent(int eventType, Bundle params) {
// Nothing
}
@Override
public void onError(int error) {
switch (error){
case SpeechRecognizer.ERROR_AUDIO:
Log.e(MainActivity,"Failed to recognize speech: Audio recording error.");
startListening(1000);
break;
case SpeechRecognizer.ERROR_CLIENT:
Log.e(MainActivity,"Failed to recognize speech: Insufficient permissions.");
startListening(1000);
break;
case SpeechRecognizer.ERROR_NO_MATCH:
Log.d(MainActivity,"Failed to recognize speech: No recognition results matched. Retrying...");
startListening(1000);
break;
default:
Log.e(MainActivity,"Failed to recognize speech. Unknown error" + error);
startListening(1000);
}
}
@Override
public void onEndOfSpeech() {
Log.d(MainActivity, "EndofSpeech");
}
@Override
public void onBufferReceived(byte[] buffer) {
//Didn´t use
}
@Override
public void onBeginningOfSpeech() {
Log.d(MainActivity, "beginnofSpeech");//Do something when speaking starts
}
};
}
The onReadyforSpeech Method is called, but after that nothing happens and than the Error is getting thrown.