30 Ekim 2017 Pazartesi

SpeechRecognizer Sınıfı

createSpeechRecognizer metodu
Şöyle yaparız.
SpeechRecognizer recog = SpeechRecognizer.createSpeechRecognizer(this);
setRecognitionListener metodu
Şöyle yaparız.
recog.setRecognitionListener(new RecogListener());
Listener şöyledir
class RecogListener implements RecognitionListener {
  @Override
  public void onBeginningOfSpeech() {...}
  @Override
  public void onRmsChanged(float rmsdB) {...}
  @Override
  public void onEndOfSpeech() {...}
  @Override
  public void onReadyForSpeech(Bundle params) {...}
  @Override
  public void onResults(Bundle data) {
    ArrayList strlist = data.getStringArrayList(SpeechRecognizer.RESULTS_RECOGNITION);
    for (int i = 0; i < strlist.size();i++ ) {
      ...
    }
  }
  @Override
  public void onPartialResults(Bundle partialResults) {...}
  @Override
  public void onEvent(int eventType, Bundle params) {...}
  @Override
  public void onBufferReceived(byte[] buffer) {...}
  @Override
  public void onError(int error) {...}
}
startListening metodu
Şöyle yaparız.
Intent intent = RecognizerIntent.getVoiceDetailsIntent(getApplicationContext());
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, "cmn-Hans-CN");
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_PREFERENCE, "cmn-Hans-CN");
intent.putExtra(RecognizerIntent.EXTRA_ONLY_RETURN_LANGUAGE_PREFERENCE, "cmn-Hans-CN");
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
  RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
intent.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE, "com.dummy");
intent.putExtra(RecognizerIntent.EXTRA_PARTIAL_RESULTS, true);
recog.startListening(intent);

Hiç yorum yok:

Yorum Gönder