Using Speech Input API

The Android SDK support an easy integration of speech input into native applications. We need just to send out an intent RecognizerIntent (no permission is required) to call any available voice recognition service in the phone (e.g. Google Voice, Nuance Dragon API for mobile). Then, a list of recognized word is send back to the application which can capture them in the onActivityResult method. Here is how to send the RecognizerIntent:
int REQUEST_CODE = 1234;
Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
                RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, Locale.ENGLISH);
intent.putExtra(RecognizerIntent.EXTRA_PROMPT, "Transalation Demo...");
startActivityForResult(intent, REQUEST_CODE);
The next code snippet shows how to handle the callback message in the onActivityResult method:
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
   if (requestCode == REQUEST_CODE && resultCode == RESULT_OK) {
      ArrayList<String> matches = intent.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
      String text = matches.get(0);
      String translated = translate(text);
      if(translated != null) {
         Toast.makeText(this, translated, Toast.LENGTH_LONG).show();
      }else {
         Toast.makeText(this, "Unable to contact translation service", Toast.LENGTH_LONG).show();
      }
   }
   super.onActivityResult(requestCode, resultCode, intent);
}
The two snippets were inspired from other interesting posts that can be found hereor here.  The Google official post on how to use Speech Input in Android through Google's Voice Search application can be found here.

DroidTranslator

As an example of using speech as user input I made an Android application that translator the user voice message from a language to another. The project is open source, this is link to the project GitHub repository. The following snapshot of the application was taken with Android Screencast.
I used the MyMemory language translation service, but there is planty of similar service, here is some available translation API:

Here is a demo of the application:

15 commentaires:

  1. Well you use a hard way for publishing, you could find much easier one!
    Click here:
    angularjs training in btm
    Click here:
    angularjs training in rajajinagar

    RépondreSupprimer
  2. Excellant post!!!. The strategy you have posted on this technology helped me to get into the next level and had lot of information in it.
    Blueprism online training

    Blue Prism Training in Pune

    Blueprism training in tambaram

    RépondreSupprimer
  3. Thanks you for sharing this unique useful information content with us. Really awesome work. keep on blogging
    Devops Training in Chennai

    Devops Training in Bangalore

    RépondreSupprimer
  4. Well done! Pleasant post! This truly helps me to discover the solutions for my inquiry. Trusting, that you will keep posting articles having heaps of valuable data. You're the best! 
    java training in marathahalli | java training in btm layout

    java training in jayanagar | java training in electronic city

    RépondreSupprimer
  5. After seeing your article I want to say that the presentation is very good and also a well-written article with some very good information which is very useful for the readers....thanks for sharing it and do share more posts like this.
    angularjs-Training in tambaram

    angularjs-Training in sholinganallur

    angularjs-Training in velachery

    angularjs Training in bangalore

    angularjs Training in bangalore

    angularjs Training in btm

    RépondreSupprimer
  6. After reading your post I understood that last week was with full of surprises and happiness for you. Congratz! Even though the website is work related, you can update small events in your life and share your happiness with us too.
    angularjs online training

    apache spark online training

    informatica mdm online training

    devops online training

    aws online training

    RépondreSupprimer
  7. Wow it is really wonderful and awesome thus it is very much useful for me to understand many concepts and helped me a lot. it is really explainable very well and i got more information from your blog.
    Microsoft Azure online training
    Selenium online training
    Java online training
    Python online training
    uipath online training

    RépondreSupprimer
  8. excellent one..nice,creative..Thanks for the Giving the Good content to making valuable more. Appreciating all of your efforts to giving such an informative Blogs.

    BEST ANGULAR JS TRAINING IN CHENNAI WITH PLACEMENT

    https://www.acte.in/angular-js-training-in-chennai
    https://www.acte.in/angular-js-training-in-annanagar
    https://www.acte.in/angular-js-training-in-omr
    https://www.acte.in/angular-js-training-in-porur
    https://www.acte.in/angular-js-training-in-tambaram
    https://www.acte.in/angular-js-training-in-velachery


    RépondreSupprimer
  9. very nice one

    BEST ANGULAR JS TRAINING IN CHENNAI WITH PLACEMENT

    https://www.acte.in/angular-js-training-in-chennai
    https://www.acte.in/angular-js-training-in-annanagar
    https://www.acte.in/angular-js-training-in-omr
    https://www.acte.in/angular-js-training-in-porur
    https://www.acte.in/angular-js-training-in-tambaram
    https://www.acte.in/angular-js-training-in-velachery


    RépondreSupprimer
  10. I am so proud of you and your efforts and work make me realize that anything can be done with patience and sincerity. Well I am here to say that your work has inspired me without a doubt.
    oracle training in chennai

    oracle training in tambaram

    oracle dba training in chennai

    oracle dba training in tambaram

    ccna training in chennai

    ccna training in tambaram

    seo training in chennai

    seo training in tambaram

    RépondreSupprimer
  11. After seeing your article I want to say that the presentation is very good and also a well-written article with some very good information which is very useful for the readers....thanks for sharing it and do share more posts like this.
    Web design Training in Chennai

    Web design Training in Velachery

    Web design Training in Tambaram

    Web design Training in Porur

    Web design Training in Omr

    Web design Training in Annanagar

    RépondreSupprimer