我正在通过 Intent 使用 SpeechRecognizer:
Intent i = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
i.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
i.putExtra(RecognizerIntent.EXTRA_PROMPT,
"straight talk please");
i.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS, 5);
i.putExtra(RecognizerIntent.EXTRA_LANGUAGE,
"en-US";
startActivityForResult(i, 0);
我在 onActivityResults() 中得到这样的结果:
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == 0 && resultCode == RESULT_OK) {
// List with the results from the Voice Recognition API
ArrayList<String> results = data
.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
// The confidence array
float[] confidence = data.getFloatArrayExtra(
RecognizerIntent.EXTRA_CONFIDENCE_SCORES);
// The confidence results
for (int i = 0; i < confidence.length; i++) {
Log.v("oAR", "confidence[" + i + "] = " + confidence[i]);
}
}
super.onActivityResult(requestCode, resultCode, data);
}
但是 float 数组总是返回 0.0 作为结果,但是第一个元素是这样的:
confidence[0] = any value between 0 and 1
confidence[1] = 0.0
confidence[2] = 0.0
and so on
我希望每个结果都有一个介于 0 和 1 之间的置信度值。否则它似乎毫无用处,因为默认情况下具有最高置信度的结果将是第一个元素,而不使用EXTRA_CONFIDENCE_SCORES
. 有什么我想念的吗?
此外,RecognizerIntent.EXTRA_CONFIDENCE_SCORES
应该在API Level 14++
. 但不管我使用哪个 API 高于 8,结果保持不变。在那一点上文档已经过时了吗?