2
我有兩個edittext框和每個按鈕。兩個按鈕上的語音識別器到兩個edittexts
當我點擊第一個按鈕時,我想調用語音識別器,結果進入第一個editext框,第二個按鈕填充第二個edittext框。
我用下面的代碼
public void speech1(View view) {
final int REQUEST_CODE = 1;
Intent i = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
i.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, "en-US");
try {
startActivityForResult(i, REQUEST_CODE);
} catch (Exception e) {
Toast.makeText(this, "Error initializing speech to text engine.", Toast.LENGTH_LONG).show();
}
}
public void speech2(View view) {
final int REQUEST_CODE = 2;
Intent i = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
i.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, "en-US");
try {
startActivityForResult(i, REQUEST_CODE);
} catch (Exception e) {
Toast.makeText(this, "Error initializing speech to text engine.", Toast.LENGTH_LONG).show();
}
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
ArrayList<String> thingsYouSaid = data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
if(REQUEST_CODE==1){
EditText editText = (EditText)findViewById(R.id.speechText1);
editText.setText(thingsYouSaid.get(0), TextView.BufferType.EDITABLE);
}
if(REQUEST_CODE==2){
EditText editText = (EditText)findViewById(R.id.speechText2);
editText.setText(thingsYouSaid.get(0), TextView.BufferType.EDITABLE);
}
}
它在正確的EditText框不會填寫剛剛離開他們的空白一直在尋找一個教程,但無法找到的兩個語音輸入
非常感謝你的作品 – user3422687