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);
}
}
請清理您的代碼。按鈕和TODO項目與您的問題並不相關。 – Kaarel 2013-02-27 19:55:01
add intent.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS,1);最大的一個結果 – Nepster 2014-05-29 11:31:35