#ACTION_RECOGNIZE_SPEECH
Explore tagged Tumblr posts
jacob-cs · 8 years ago
Text
Android wear 개발 방법 (Obtaining Free-form Speech Input)
original source : http://www.androiddocs.com/training/wearables/apps/voice.html
사용자로부터 음성으로 data입력을 받으려는 경우
Obtaining Free-form Speech Input
In addition to using voice actions to launch activities, you can also call the system's built-in Speech Recognizer activity to obtain speech input from users. This is useful to obtain input from users and then process it, such as doing a search or sending it as a message.
In your app, you call
startActivityForResult()
using the
ACTION_RECOGNIZE_SPEECH
action. This starts the speech recognition activity, and you can then handle the result in
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);
1 note · View note
jacob-cs · 8 years ago
Link
original source: https://stackoverflow.com/questions/18329104/recognizerintent-change-default-language
String language =  "us-US"; Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH); intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,language); intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, language); intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_PREFERENCE, language); intent.putExtra(RecognizerIntent.EXTRA_ONLY_RETURN_LANGUAGE_PREFERENCE, language); startActivityForResult(intent, RESULT_SPEECH_GUEST);
0 notes
jacob-cs · 8 years ago
Text
Android wear 개발방법(Adding Voice Capabilities)
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">      <intent-filter>          <action android:name="android.intent.action.SEND" />          <category android:name="com.google.android.voicesearch.SELF_NOTE" />      </intent-filter>  </activity>
몇몇의 voice intent의 예시들
Tumblr media
더 많은 voice intent를 참조하려명  see Common intents.
Declare App-provided Voice Actions
you can start your apps directly with a "Start MyActivityName" voice action.
<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>
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);    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); }
startActivityForResult() 를 통해 음성으로 입력값을 받을 activity를 실행한다.이때 action은  ACTION_RECOGNIZE_SPEECH 으로 지정한다. 그리고 그 결과는  onActivityResult() 에서 받을수 있다.
0 notes