It's hard for me to handle this. I'm just trying to find all available languages ββsupported by speech recognition, as well as code for using it.
Exist
RecognizerIntent.EXTRA_SUPPORTED_LANGUAGES
which should report all available languages ββon the G speech servers as an array. Unfortunately, I can't even spit it out. I basically just have problems with BroadcastReceiver, I think.
package com.thatll.ddo;
import java.util.ArrayList;
import java.util.logging.Logger;
import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.speech.RecognizerIntent;
import android.util.Log;
import android.widget.Toast;
public class RecogtestActivity extends Activity {
private static final int VOICE_RECOGNITION_REQUEST_CODE = 1234;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Log.i("Log", "startVoiceRecognitionActivity");
Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
intent.putExtra(RecognizerIntent.EXTRA_PROMPT, "speech recognition demo");
startActivityForResult(intent, VOICE_RECOGNITION_REQUEST_CODE);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == VOICE_RECOGNITION_REQUEST_CODE && resultCode == RESULT_OK) {
Intent intent = new Intent(RecognizerIntent.ACTION_GET_LANGUAGE_DETAILS);
LangBroadcastReceiver myBroadcastReceiver = new LangBroadcastReceiver(this, data.getStringArrayListExtra(RecognizerIntent.EXTRA_SUPPORTED_LANGUAGES));
sendOrderedBroadcast(intent, null, myBroadcastReceiver, null, Activity.RESULT_OK, null, null);
} else {
Toast.makeText(getApplicationContext(), "Voice recognition failed.", Toast.LENGTH_LONG).show();
}
super.onActivityResult(requestCode, resultCode, data);
}
public class LangBroadcastReceiver extends BroadcastReceiver {
ArrayList<String> recognisedText;
Activity parentActivity;
LangBroadcastReceiver(Activity activity, ArrayList<String> arrayList) {
recognisedText = arrayList;
parentActivity = activity;
}
@Override
public void onReceive(Context context, Intent intent) {
Bundle results = getResultExtras(true);
String lang = results.getString(RecognizerIntent.EXTRA_SUPPORTED_LANGUAGES);
Log.d("log", "MyBroadcastReceiver: Got 'EXTRA_LANGUAGE_PREFERENCE' = " + lang);
ArrayList<CharSequence> hints = getResultExtras(true)
.getCharSequenceArrayList(
RecognizerIntent.EXTRA_SUPPORTED_LANGUAGES);
Log.d("log", "MyBroadcastReceiver: Got 'EXTRA_LANGUAGE_PREFERENCE' = " + hints);
}
}}
I would like to know why this does not work, but for now I would be just as happy if I got a complete list of supported languages. Tried various methods, and now I'm starting to annoy me.
Thanks for any help
source
share