0
我需要關於android語音文本的幫助。是否有可能僅顯示檢測到的第一個單詞?就像用戶輸入「貓正在播放」時一樣,那麼僅出現在文本框上的文本就是單詞「the」。Android脫機語音識別僅顯示文字
,我使用的代碼:
protected static final int RESULT_SPEECH = 1;
private Button btn_mic;
private TextView txtText;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.basic_level1);
txtText = (TextView) findViewById(R.id.txt);
btn_mic = (Button) findViewById(R.id.mic);
btn_mic.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, "en-US");
try {
startActivityForResult(intent, RESULT_SPEECH);
txtText.setText("");
} catch (ActivityNotFoundException a) {
Toast t = Toast.makeText(getApplicationContext(),
"Opps! Your device doesn't support Speech to Text",
Toast.LENGTH_SHORT);
t.show();
}
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main_menu, menu);
return true;
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
switch (requestCode) {
case RESULT_SPEECH: {
if (resultCode == RESULT_OK && null != data) {
ArrayList<String> text = data
.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
txtText.setText(text.get(0));
}
break;
}
}
}
}
在此先感謝。 :)
[離線語音識別的Android(豆形軟糖)(http://stackoverflow.com/questions/17616994/offline-speech-recognition-in-android-jellybean) – Gattsu 2014-11-25 13:27:22