我想通过语音转文本(STT)在我的列表视图中搜索。我有一个城市列表,现在当用户通过 STT 搜索时。此搜索仅适用于我的列表视图(如 STT 联系人搜索),
问问题
1770 次
2 回答
2
Speech to Text is built into Android 1.6+. Here is a simple example of how to do it.
/**
* Showing google speech input dialog
* */
private void promptSpeechInput() {
Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, Locale.getDefault());
intent.putExtra(RecognizerIntent.EXTRA_PROMPT,
getString(R.string.speech_prompt));
try {
startActivityForResult(intent, REQ_CODE_SPEECH_INPUT);
} catch (ActivityNotFoundException a) {
Toast.makeText(getApplicationContext(),
getString(R.string.speech_not_supported),
Toast.LENGTH_SHORT).show();
}
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
switch (requestCode) {
case REQ_CODE_SPEECH_INPUT: {
if (resultCode == RESULT_OK && null != data) {
ArrayList<String> result = data
.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
txtSpeechInput.setText(result.get(0));
}
break;
}
}
}
More info: http://www.androidhive.info/2014/07/android-speech-to-text-tutorial/
Updated:
Try this code for filter view.
http://www.androidhive.info/2012/09/android-adding-search-functionality-to-listview/
于 2014-11-01T10:45:44.883 回答
0
在我们的应用程序中查看此代码Google Voice
/* Google Voice open while calling Activity */
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
/* Call Activity to Open Google Voice */
Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, "en-US");
try {
startActivityForResult(intent, 1);
} catch (ActivityNotFoundException a) {
Log.d("LOG",a.getMessage());
}
}
/* This will be called after you speak */
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
switch (requestCode) {
case 1: {
if (resultCode == Activity.RESULT_OK && null != data) {
ArrayList text = data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
Log.d("LOG","You have speak : "+text.get(0));
}
break;
}
}
}
您将获得text.get(0)
可用于过滤的语音字符串的结果ListView
。
notifyDataSetChanged()
ListView
对于使用新数据进行更改很有用。
于 2014-11-01T11:25:06.743 回答