Home | History | Annotate | Download | only in articles
      1 page.title=Speech Input
      2 parent.title=Articles
      3 parent.link=../browser.html?tag=article
      4 @jd:body
      5 
      6 <p> People love their mobile phones because they can stay in touch wherever they
      7 are.  That means not just talking, but e-mailing, texting, microblogging, and so
      8 on. </p>
      9 
     10 <p>Speech input adds another dimension to staying in touch.
     11 Google's Voice Search application, which is pre-installed on many Android devices
     12 and available in Android Market, provides powerful features like "search by voice"
     13 and Voice Actions like "Navigate to." Further
     14 enhancing the voice experience, Android 2.1 introduces a <a
     15 href="http://www.youtube.com/watch?v=laOlkD8LmZw">
     16 voice-enabled keyboard</a>, which makes it even easier
     17 to stay connected. Now you can dictate your message instead of typing it. Just
     18 tap the new microphone button on the keyboard, and you can speak in just about
     19 any context in which you would normally type. </p> 
     20 
     21 <p> We believe speech can
     22 fundamentally change the mobile experience. We would like to invite every
     23 Android application developer to consider integrating speech input capabilities
     24 via the Android SDK.  One of our favorite apps in the Market that integrates
     25 speech input is <a href="http://www.handcent.com/">Handcent SMS</a>, 
     26 because you can dictate a reply to any SMS with a
     27 quick tap on the SMS popup window. Here is Speech input integrated into
     28 Handcent SMS:</p>
     29 
     30 <img src="images/speech-input.png"/>
     31 
     32 
     33 <p> The Android SDK makes it easy to integrate speech input directly into your
     34 own application. Just copy and paste from this <a
     35 href="{@docRoot}resources/samples/ApiDemos/src/com/example/android/apis/app/VoiceRecognition.html">sample
     36 application</a> to get
     37 started. The sample application first verifies that the target device is able
     38 to recognize speech input:</p> 
     39 <pre>
     40 // Check to see if a recognition activity is present
     41 PackageManager pm = getPackageManager();
     42 List<ResolveInfo> activities = pm.queryIntentActivities(
     43   new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH), 0);
     44 if (activities.size() != 0) {
     45   speakButton.setOnClickListener(this);
     46 } else {
     47   speakButton.setEnabled(false);
     48   speakButton.setText("Recognizer not present");
     49 }
     50 </pre>
     51 <p>
     52 The sample application then uses {@link
     53 android.app.Activity#startActivityForResult(android.content.Intent, int)
     54 startActivityForResult()} to broadcast an intent that requests voice
     55 recognition, including an extra parameter that specifies one of two language
     56 models. The voice recognition application that handles the intent processes the
     57 voice input, then passes the recognized string back to your application by
     58 calling the {@link android.app.Activity#onActivityResult(int, int,
     59 android.content.Intent) onActivityResult()} callback. </p>
     60 
     61 
     62 <p>Android is an open platform, so your application can potentially make
     63 use of any speech recognition service on the device that's registered to receive
     64 a {@link android.speech.RecognizerIntent}. Google's Voice Search application,
     65 which is pre-installed on
     66 many Android devices, responds to a <em>RecognizerIntent</em> by displaying the
     67 "Speak
     68 now" dialog and streaming audio to Google's servers -- the same servers used
     69 when a user taps the microphone button on the search widget or the voice-enabled
     70 keyboard. You can check whether Voice Search is installed in 
     71 <strong>Settings > Applications > Manage applications</strong>. </p>
     72 
     73 <p> One important tip: for speech input to be as accurate as possible, it's
     74 helpful to have an idea of what words are likely to be spoken.  While a message
     75 like "Mom, I'm writing you this message with my voice!" might be appropriate for
     76 an email or SMS message, you're probably more likely to say something like
     77 "weather in Mountain View" if you're using Google Search. You can make sure your
     78 users have the best experience possible by requesting the appropriate
     79 <em>language model:</em> {@link
     80 android.speech.RecognizerIntent#LANGUAGE_MODEL_FREE_FORM free_form} for
     81 dictation, or {@link android.speech.RecognizerIntent#LANGUAGE_MODEL_WEB_SEARCH
     82 web_search} for shorter, search-like phrases.  We developed the "free form"
     83 model to improve dictation accuracy for the voice keyboard,
     84 while the "web search" model is used when users want to search by voice. </p> 
     85 
     86 <p> Google's servers support many languages for voice input, with more arriving
     87 regularly. You can use the
     88 {@link android.speech.RecognizerIntent#ACTION_GET_LANGUAGE_DETAILS}
     89 broadcast intent to query for the list of supported languages.
     90 The web search model is available for all languages, while the free-form model
     91 may not be optimized for all languages. As we work hard to support more models in
     92 more languages, and to improve the accuracy of the speech recognition technology
     93 we use in our products, Android developers who integrate speech capabilities
     94 directly into their applications can reap the benefits as well. </p>
     95