I'm making a speech to text / text to speech extension for android with gamemaker: studio and altho the text to speech works perfect,( check my android apk out and you will see text to speech- perfect, speech to text- broken) getting speech to text doesn't work, it is not getting the results from the onActivityResult method, as shown by the absence of my Log.i entry that I put in the onActivityResult method in the debug window. Can any of you help me out as to why? I have tried the following in countless different ways but with no luck, I've looked at literally 100 threads in here having to do with onActivityResults and tried implementing their solutions (but java is either not to be set up the same when combined with gamemaker, or the runner library used by gm:s isn't compatible or something would have worked) what am I doing wrong? I've also looked at an extension that works with using onActivityResult fired by an intent with EXTRAs, (the extension was for picking media files from android device) and I tried setting it up exactly like they did except using my recognizerIntent, but it still doesn't work for speech recognition, Is this something that gamemakers runner library isn't set up to handle? is the on activity result somehow different for returning speech data than returning data from images selected? in this case they both require a request code, a result code and intent data with extras so I don't see what is going on here as to why it doesn't work. Also is there some technical documentation somewhere you can point me to that describes GM:S's runner library and how it works? here's the relative codes to how I have it set up:
GAMEMAKER(gml) left mouse press event:
getMic();
EXTENSION(Java) get the microphone for listning:
public void getMic() {
Log.i("yoyo", "Listening for speech");
try {
j = new Intent();
j.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
j.putExtra(RecognizerIntent.EXTRA_LANGUAGE, Locale.getDefault());
j.putExtra(RecognizerIntent.EXTRA_PROMPT, "Say something");
j.setAction(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
RunnerActivity.CurrentActivity.startActivityForResult(j, 100);
Log.i("yoyo", "send to onActivityResult, Data: " + String.valueOf(j));
} catch (ActivityNotFoundException a) {
Log.i("yoyo", "Your device doesn't support Speech Recognition");
}
}
The google speak now dialog pops up, i speak, it beeps confirming i spoke and disappears as it should
EXTENSION(java) get our results from speaking and save them internally:
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
Log.i("yoyo", "onActivityResult, requestCode: " + requestCode + ", resultCode: " + resultCode);
(RunnerActivity.CurrentActivity).onActivityResult(requestCode, resultCode, data);
if(requestCode == 100){
if (resultCode == RESULT_OK && data != null) {
ArrayList<String> res = data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
holdForGMS = String.valueOf(res.get(0));
editor.putString(GETMYSPEECH, holdForGMS).apply();
}
}
}
GAMEMAKER(gml)
retrieve the results from memory GMS side, in alarm event that fires after speaking:
if global.isSpeaking=1 findMySpeech();
global.isSpeaking=0;
EXTENSION(java)
findMySpeach method:
public void findMySpeech() {
String gmsar = preferences.getString(GETMYSPEECH,"");
Log.i("yoyo", "Spoken words- " + gmsar);
recognition(gmsar);
}
aaaaannnd it's gone. the log results show it got a result (got activity result -1) but never fired the onActivityResult, which of course didn't save the result in the preference editor either, here is the log and a flow chart: