android2018. 7. 11. 16:13
간단히 voice input을 Toast로 출력하는 예제

/* Call Activity for Voice Input */
Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);

intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, "en-US");

try {
    startActivityForResult(intent, 1);
} catch (ActivityNotFoundException a) {
    Toast.makeText(context, "Oops! Your device doesn't support Speech to Text",Toast.LENGTH_SHORT).show();
}


/* When Mic activity close */

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    switch (requestCode) {
    case 1: {
        if (resultCode == Activity.RESULT_OK && null != data) {
            String yourResult = data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS).get(0);
        }
        break;
    }
    }
}

출처 : https://stackoverflow.com/questions/18049157/how-to-programmatically-initiate-a-google-now-voice-search?lq=1

'android' 카테고리의 다른 글

custom view tutorial 따라하기 2  (0) 2018.07.13
custom view tutorial 따라하기 1  (0) 2018.07.12
Simple voice search test  (0) 2018.07.11
NDK API는 binder를 지원하지 않는다.  (0) 2018.07.03
hidl simple example  (4) 2018.06.25
Posted by easy16