これを機能させるのに苦労しています。音声認識でサポートされている利用可能なすべての言語と、それを使用するコードを見つけようとしています。
がある
RecognizerIntent.EXTRA_SUPPORTED_LANGUAGES
G の音声認識サーバーで利用可能なすべての言語を配列として報告する必要があります。残念ながら、吐き出すことさえできません。私は主に BroadcastReceiver に問題があると思います。
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;
/** Called when the activity is first created. */
@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);
}
/**
* After a voice recognition is performed, need to sent a broadcast to
* request the language used. This BroadcastReceiver gets the response and
* then processes the original recognisedText from the
* ACTION_RECOGNIZE_SPEECH Intent.
*
*/
public class LangBroadcastReceiver extends BroadcastReceiver {
ArrayList<String> recognisedText;
Activity parentActivity;
/**
* Store these for later use...
* @param activity
* @param arrayList
*/
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);
// now handle the recognisedText with the known language.
ArrayList<CharSequence> hints = getResultExtras(true)
.getCharSequenceArrayList(
RecognizerIntent.EXTRA_SUPPORTED_LANGUAGES);
Log.d("log", "MyBroadcastReceiver: Got 'EXTRA_LANGUAGE_PREFERENCE' = " + hints);
}
}}
これが機能しない理由を知りたいのですが、現時点では、現在サポートされている言語の完全なリストを入手できれば幸いです. さまざまな方法を試してみましたが、今では私を悩ませ始めています。
助けてくれてありがとう