1

当通过 Chrome 的 HTML 5 语音输入支持使用 Google 的服务器进行语音识别时,您每次得到大约 6 个结果,即用户语音音频的 6 种可能解释。我只想要一个结果,我该怎么做?

这是我的代码:

    package com.emanrox.tutorialbasics12;

    import java.util.ArrayList;

    import android.app.Activity;
    import android.content.Intent;
    import android.os.Bundle;
    import android.speech.RecognizerIntent;
    import android.view.View;
    import android.view.View.OnClickListener;
    import android.widget.ArrayAdapter;
    import android.widget.Button;
    import android.widget.ListView;

    public class Voice extends Activity implements OnClickListener {

ListView lv;
static final int check = 1111;


@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.voice);
    lv = (ListView)findViewById(R.id.lvVoiceReturn);
    Button b = (Button)findViewById(R.id.bVoice);
    b.setOnClickListener(this);

}

@Override
public void onClick(View arg0) {
    // TODO Auto-generated method stub
Intent i = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
i.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,                   RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
i.putExtra(RecognizerIntent.EXTRA_PROMPT, "Speak up son!");
startActivityForResult(i, check);
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
            // TODO Auto-generated method stub
if (requestCode == check && resultCode == RESULT_OK){
    ArrayList<String> results = data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
    lv.setAdapter(new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,results));


}



    super.onActivityResult(requestCode, resultCode, data);
}

}

4

1 回答 1

1

也许将MAX_RESULTS 额外设置为1.

我不确定您的代码与 Chrome HTML 5 语音输入之间的关系是什么。为什么你不能直接丢弃额外的结果?有时,服务更容易提供多个结果,然后客户必须对它们进行后处理......

于 2013-02-27T19:53:28.387 回答