How to get instance is call createSpeechRecognizer(Context);
SpeechRecognizer sr = SpeechRecognizer.createSpeechRecognizer(getApplicationContext());and make listener class,
class MyRecognitionListener implements RecognitionListener { @Override public void onBeginningOfSpeech() { Log.d("Speech", "onBeginningOfSpeech"); } @Override public void onBufferReceived(byte[] buffer) { Log.d("Speech", "onBufferReceived"); } @Override public void onEndOfSpeech() { Log.d("Speech", "onEndOfSpeech"); } @Override public void onError(int error) { Log.d("Speech", "onError"); } @Override public void onEvent(int eventType, Bundle params) { Log.d("Speech", "onEvent"); } @Override public void onPartialResults(Bundle partialResults) { Log.d("Speech", "onPartialResults"); } @Override public void onReadyForSpeech(Bundle params) { Log.d("Speech", "onReadyForSpeech"); } @Override public void onResults(Bundle results) { Log.d("Speech", "onResults"); ArrayListthe important method is onResults. There is recognized word in "results".strlist = results.getStringArrayList(SpeechRecognizer.RESULTS_RECOGNITION); for (int i = 0; i < strlist.size();i++ ) { Log.d("Speech", "result=" + strlist.get(i)); } } @Override public void onRmsChanged(float rmsdB) { Log.d("Speech", "onRmsChanged"); } }
public void onResults(Bundle results) { Log.d("Speech", "onResults"); ArrayListI make the listener.strlist = results.getStringArrayList(SpeechRecognizer.RESULTS_RECOGNITION); for (int i = 0; i < strlist.size();i++ ) { Log.d("Speech", "result=" + strlist.get(i)); } }
MyRecognitionListener listener = new MyRecognitionListener();I set listener.
sr.setRecognitionListener(listener);I start speech recognizing.
sr.startListening(RecognizerIntent.getVoiceDetailsIntent(getApplicationContext()));onResults() call only once.
I said "english".
logcat printed.
result=リング result=english result=ring result=イング result=ingIt is OK!
I must have android.permission.RECORD_AUDIO. and network is enable. source code is here. Please suggest your android issue by twitter or mail, I would try to clear up your issue.
Thank you for posting this. This is the only good example I've been able to find for SpeechRecognizer.
返信削除