问题
I am interested in speech recognition in Android but I can't do it: it is not continuous. If you stop speaking, it doesn't continue, and you have to click on the button again.
I do not want this behaviour..
Does anybody have any suggestions as to what I can to fix this?
Recognise speech only first time I do not want this behaviour.
Here is the code:
private SpeechRecognizer speech;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
speech = SpeechRecognizer.createSpeechRecognizer(this);
speech.setRecognitionListener(this);
Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_PREFERENCE, "en");
intent.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE,
this.getPackageName());
speech.startListening(intent);
}
@Override
public void onBeginningOfSpeech()
{
}
@Override
public void onBufferReceived(byte[] arg0)
{
}
@Override
public void onEndOfSpeech()
{
}
@Override
public void onError(int e)
{
}
@Override
public void onEvent(int arg0, Bundle arg1)
{
}
@Override
public void onPartialResults(Bundle arg0)
{
}
public void onReadyForSpeech(Bundle arg0)
{
}
@Override
public void onResults(Bundle data)
{
ArrayList<String> matches = data.getStringArrayList(
SpeechRecognizer.RESULTS_RECOGNITION);
}
@Override
public void onRmsChanged(float arg0)
{
}
回答1:
Try to call again
speech.startListening(intent);
inside On Results and OnError.
来源:https://stackoverflow.com/questions/32531721/speech-only-first-time