original source: https://developer.android.com/training/wearables/apps/voice.html

두종류의 voice action types

  • System-provided  이미 시스템상에서 지정된 voice action
  • App-provided  app에서 지정하거나 특정 app의 activity를 실행하는 경우

Declare System-provided Voice Actions

When users speak the voice action, your app can filter for the intent that is fired to start an activity. If you want to start a service to do something in the background, show an activity as a visual cue and start the service in the activity. Make sure to call finish() when you want to get rid of the visual cue.

<activity android:name="MyNoteActivity">
         <action android:name="android.intent.action.SEND" />
         <category android:name="com.google.android.voicesearch.SELF_NOTE" />

몇몇의 voice intent의 예시들

더 많은 voice intent를 참조하려명 

see Common intents.

Declare App-provided Voice Actions

you can start your apps directly with a “Start MyActivityName” voice action.

 <activity android:name="StartRunActivity" android:label="MyRunningApp">
         <action android:name="android.intent.action.MAIN" />
         <category android:name="android.intent.category.LAUNCHER" />

label에 해당하는 내용이 Start 다음에 들어갈 명령어에 해당한다.

Obtaining Free-form Speech Input(사용자로 부터 음성으로 입력값을 받는 방법)

private static final int SPEECH_REQUEST_CODE = 0;

// Create an intent that can start the Speech Recognizer activity
private void displaySpeechRecognizer() {
   Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
// Start the activity, the intent will be populated with the speech text
   startActivityForResult(intent, SPEECH_REQUEST_CODE);

// This callback is invoked when the Speech Recognizer returns.
// This is where you process the intent and extract the speech text from the intent.
protected void onActivityResult(int requestCode, int resultCode,
       Intent data) {
   if (requestCode == SPEECH_REQUEST_CODE && resultCode == RESULT_OK) {
       List<String> results = data.getStringArrayListExtra(
       String spokenText = results.get(0);
       // Do something with spokenText
   super.onActivityResult(requestCode, resultCode, data);

startActivityForResult() 를 통해 음성으로 입력값을 받을 activity를 실행한다.이때 action은 

ACTION_RECOGNIZE_SPEECH 으로 지정한다. 그리고 그 결과는 

onActivityResult() 에서 받을수 있다.

Comments are closed.

Post Navigation