Ste*_*ett 18 android speech-recognition
我通过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);
Run Code Online (Sandbox Code Playgroud)
我在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);
}
Run Code Online (Sandbox Code Playgroud)
但是float数组总是返回0.0,但第一个元素是这样的:
confidence[0] = any value between 0 and 1
confidence[1] = 0.0
confidence[2] = 0.0
and so on
Run Code Online (Sandbox Code Playgroud)
我希望每个结果的置信度值介于0和1之间.否则它似乎没用,因为具有最高置信度的结果将是默认情况下的第一个元素,而不使用EXTRA_CONFIDENCE_SCORES.有什么我想念的吗?
此外,RecognizerIntent.EXTRA_CONFIDENCE_SCORES它应该被用于API Level 14++.但是我使用它的8个以上的API无关紧要,结果保持不变.在那一点上,文档是否过时了?
我没有从事过语音重组方面的工作。但是,正如您所说,您得到的浮点数组值为 0.0,这意味着float array is null. 您能检查一下 float[] 是否返回 null 或者其他吗?
ArrayList<String> results = data\n .getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);\n\nfloat[] confidence = data.getFloatArrayExtra(\n RecognizerIntent.EXTRA_CONFIDENCE_SCORES);\nif (confidence == null)\n{\n for (int i = 0; i < results.size(); i++)\n {\n Log.d(TAG, i + ": " + results.get(i));\n }\n}\nelse\n{\n for (int i = 0; i < results.size(); i++)\n\n {\n Log.d(TAG, i + ": " + heard.get(i) + " confidence : " + confidence[i]);\n }\n}\nRun Code Online (Sandbox Code Playgroud)\n\n您可以查看Greg Milette、Adam Stroud 撰写的《专业 Android 传感器编程 \xc2\xa0》一书吗?这肯定会对您有所帮助。您将在本书第 394页获得一些详细信息。
\n| 归档时间: |
|
| 查看次数: |
3577 次 |
| 最近记录: |