음성 기능 추가

음성 작업은 웨어러블 경험에서 중요한 부분이다. 그것들은 사용자에게 작업을 핸즈프리와 빠른게 해준다. 웨어러블은 두 가지 종류의 음성 작업을 제공한다:

시스템-제공
이 음성 작업은 작업 기반이고, 웨어러블 플랫폼에 빌드 되어있다. 음성 작업이 가능할 때 시작하기를 원하면 액티비티내에서 그것들을 필터링 할 수 있다. 예제들은 "메모하기" 혹은 "알람 설정"을 포함한다.
앱-제공
이 음성 작업은 앱 기반이고, 당신은 그것들을 실행 아이콘처럼 선언해야한다. 사용자는 이러한 음성 작업을 및 특정 시작을 지정하는 액티비티의 사용을 위해 "시작" 이라고 말해야한다.

시스템-제공 음성 작업 선언


안드로이드 웨어러블 플랫폼은 "메모하기" 혹은 "알람 설정" 등과 같은 사용자 작업에 기반한 여러가지 음성 intents를 제공한다. 이는 사용자들이 하기를 원하는 것과 시스템이 시작하기 위해 최적의 액티비티를 알아내도록 말하는 것을 허용한다.

사용자가 음성 작업을 말했을 때, 당신의 앱은 액티비티를 시작하기 위해 점화된 인텐트의 필터링이 가능하다. 만약 당신이 배경화면 안에서 무언가를 위해 서비스를 시작하길 원한다면, 시작적으로 액티비티를 보여주고, 액티비티 내에서 서비스를 시작하라. 당신이 시각적인 것을 제거하길 원할 때 반드시 finish()를 호출해야한다.

예를들어 "메모하기" 명령을 위해, MyNoteActivity라고 명명된 액티비티의 시작을 위해 intent 필터를 선언하라:

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

웨어러블 플랫폼에 지원되는 음성 intent들의 목록이다:

이름

문구 예

Intent

차 호출
/
택시

"OK Google, get me a taxi"

"OK Google, call me a car"
Action
com.google.android.gms.actions.RESERVE_TAXI_RESERVATION
메모하기"OK Google, take a note"

"OK Google, note to self"
Action
android.intent.action.SEND
Category
com.google.android.voicesearch.SELF_NOTE
Extras
android.content.Intent.EXTRA_TEXT - 메모가 바디로 이루어진 문자열
알람
설정
"OK Google, set an alarm for 8 AM"

"OK Google, wake me up at 6 tomorrow"
Action
android.intent.action.SET_ALARM
Extras
android.provider.AlarmClock.EXTRA_HOUR - 알람 시간으로 이루어진 integer.

android.provider.AlarmClock.EXTRA_MINUTES - 알람 분으로 이루어진 integer

(이 두 extras는 선택사항임, 선택하지 않거나 두가지 모두 제공됨)

타이머 설정"Ok Google, set a timer for 10 minutes"
Action
android.intent.action.SET_TIMER
Extras
android.provider.AlarmClock.EXTRA_LENGTH - 타이머의 길이를 나타내는 1에서 86400(24시간을 초로 환산) 범위의 integer

자전거 타기
시작/ 중지

"OK Google, start cycling"

"OK Google, start my bike ride"

"OK Google, stop cycling"
Action
vnd.google.fitness.TRACK
Mime Type
vnd.google.fitness.activity/biking
Extras
actionStatus - 시작할 때의 ActiveActionStatus 값과 중지할 때의 CompletedActionStatus 값의 문자열

달리기 시작/
중지

"OK Google, track my run"

"OK Google, start running"

"OK Google, stop running"
Action
vnd.google.fitness.TRACK
MimeType
vnd.google.fitness.activity/running
Extras
actionStatus - 시작할 때의 ActiveActionStatus 값과 중지할 때의 CompletedActionStatus 값의 문자열
운동 시작/중지"OK Google, start a workout"

"OK Google, track my workout"

"OK Google, stop workout"
Action
vnd.google.fitness.TRACK
MimeType
vnd.google.fitness.activity/other
Extras
actionStatus - 시작할 때의 ActiveActionStatus 값과 중지할 때의 CompletedActionStatus 값의 문자열

심박수보기

"OK Google, what’s my heart rate?"

"OK Google, what’s my bpm?"
Action
vnd.google.fitness.VIEW
Mime Type
vnd.google.fitness.data_type/com.google.heart_rate.bpm
걸음수보기"OK Google, how many steps have I taken?"

"OK Google, what’s my step count?"
Action
vnd.google.fitness.VIEW
Mime Type
vnd.google.fitness.data_type/com.google.step_count.cumulative

플랫폼 intents의 등록 및 그것들 안에 포함된 추가 정보 접근의 문서는 Common intents를 참조하라.

앱-제공 음성 작업 선언


만약 플랫폼 음성 intents 중 단 하나도 당신을 위한 작업이 없다면, "Start MyActivityName" 음성 작업으로 당신의 앱을 직접 시작할 수 있다.

"Start" 작업의 등록은 휴대용 장치에서 런쳐 아이콘을 등록하는 것과 같다. 런쳐 안의 앱 아이콘 요청 대신, 당신의 앱은 음성 작업을 요청한다.

"Start" 라고 말한 뒤 텍스트를 지정하기 위해, 당신이 시작하기 원하는 액티비티의 label 속성을 지정하라. 예를들어, 이 intent 필터는 "Start MyRunningApp" 음성 작업을 인지하고 StartRunActivity를 실행한다.

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

자유로운 형식의 음성 입력 취득


당신은 액티비티들을 실행하기 위해 음성 작업을 사용할 뿐만 아니라, 사용자로부터 음성 입력을 얻기 위해 시스템 내장의 음성 인식 액티비티를 호출할 수도 있다. 이는 가령 검색하기 혹은 메시지 전송과 같은 사용자로부터의 입력을 얻거나 그것을 처리하는데에 유용하다.

당신의 앱에서 ACTION_RECOGNIZE_SPEECH 작업을 사용하여 startActivityForResult()를 호출한다. 이는 음성 인식 액티비티를 시작하고, 그러면 당신은 onActivityResult() 내에서 결과를 처리할 수 있다.

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);
    intent
.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
           
RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
// 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.
@Override
protected void onActivityResult(int requestCode, int resultCode,
       
Intent data) {
   
if (requestCode == SPEECH_REQUEST_CODE && resultCode == RESULT_OK) {
       
List<String> results = data.getStringArrayListExtra(
               
RecognizerIntent.EXTRA_RESULTS);
       
String spokenText = results.get(0);
       
// Do something with spokenText
   
}
   
super.onActivityResult(requestCode, resultCode, data);
}


'Android - Building Apps for Wearables > Creating Wearable Apps' 카테고리의 다른 글

Debugging over Bluetooth  (0) 2014.09.10
Packaging Wearable Apps  (0) 2014.09.10
Creating Custom Layouts  (0) 2014.09.10
Creating and Running a Wearable App  (0) 2014.09.10
Creating Wearable Apps  (0) 2014.08.21
Posted by 레미파
,