我正在尝试制作一个示例应用来逐字逐句展示。到目前为止,我能够实现语音识别,识别已经说过但我希望我的应用程序开始识别并输入单词,而不是等待用户完成短语或行。我知道它在Android中的可能性,因为我一直在我的短信应用程序中使用它。到目前为止我发现的教程中显示了我不希望在我的应用程序中使用的Google Dialog。
任何帮助都会非常感激。
到目前为止,这是我的代码,它显示了用户刚刚说过的内容,没有任何问题: -
public class SpeechActivity extends Activity implements RecognitionListener, View.OnClickListener {
private EditText editText;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
editText = (EditText)findViewById(R.id.abc);
findViewById(R.id.bca).setOnClickListener(this);
}
@Override
public void onReadyForSpeech(Bundle params) {
Log.e("Speech", "Ready");
}
@Override
public void onBeginningOfSpeech() {
Log.e("Speech", "Begin");
}
@Override
public void onRmsChanged(float rmsdB) {
Log.e("Speech", "Rms");
}
@Override
public void onBufferReceived(byte[] buffer) {
Log.e("Speech", "Buffer Received");
}
@Override
public void onEndOfSpeech() {
Log.e("Speech", "End");
}
@Override
public void onError(int error) {
Log.e("Speech", "Error");
}
@Override
public void onResults(Bundle results) {
Log.e("Speech", "Result");
if(results != null) {
Log.e("Speech", results.getStringArrayList(SpeechRecognizer.RESULTS_RECOGNITION).toString());
ArrayList<String> result = results.getStringArrayList(SpeechRecognizer.RESULTS_RECOGNITION);
editText.setText(result.get(0));
}
}
@Override
public void onPartialResults(Bundle partialResults) {
Log.e("Speech", "Partial Result");
if(partialResults != null) {
Log.e("Speech", partialResults.getStringArrayList(SpeechRecognizer.RESULTS_RECOGNITION).toString());
ArrayList<String> result = partialResults.getStringArrayList(SpeechRecognizer.RESULTS_RECOGNITION);
editText.setText(result.get(0));
}
}
@Override
public void onEvent(int eventType, Bundle params) {
Log.e("Speech", "OnEvent");
}
@Override
public void onClick(View v) {
SpeechRecognizer speechRecognizer = SpeechRecognizer.createSpeechRecognizer(this);
Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
intent.putExtra(RecognizerIntent.EXTRA_PROMPT, "AndroidBite Voice Recognition...");
intent.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE,
this.getPackageName());
speechRecognizer.setRecognitionListener(this);
speechRecognizer.startListening(intent);
}
}
但正如我所说,我希望我的应用程序逐字识别,并且我不希望它等到用户说完之后。
请帮助!!