Speech to text app


Last Updated:

  1. ajith19

    ajith19 New Member This Topic's Starter

    Joined:
    Aug 22, 2010
    Messages:
    2
    Likes Received:
    0
    I want to create speech to text app,to get started i got sample code from android developer site like this..
    package com.example.android.apis.app;

    package com.example.android.apis.app;

    import com.example.android.apis.R;

    import android.app.Activity;
    import android.content.Intent;
    import android.content.pm.PackageManager;
    import android.content.pm.ResolveInfo;
    import android.os.Bundle;
    import android.speech.RecognizerIntent;
    import android.view.View;
    import android.view.View.OnClickListener;
    import android.widget.ArrayAdapter;
    import android.widget.Button;
    import android.widget.ListView;

    import java.util.ArrayList;
    import java.util.List;

    /**
    * Sample code that invokes the speech recognition intent API.
    */
    public class VoiceRecognition extends Activity implements OnClickListener {

    private static final int VOICE_RECOGNITION_REQUEST_CODE = 1234;

    private ListView mList;

    /**
    * Called with the activity is first created.
    */
    @Override
    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // Inflate our UI from its XML layout description.
    setContentView(R.layout.voice_recognition);

    // Get display items for later interaction
    Button speakButton = (Button) findViewById(R.id.btn_speak);

    mList = (ListView) findViewById(R.id.list);

    // Check to see if a recognition activity is present
    PackageManager pm = getPackageManager();
    List<ResolveInfo> activities = pm.queryIntentActivities(
    new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH), 0);
    if (activities.size() != 0) {
    speakButton.setOnClickListener(this);
    } else {
    speakButton.setEnabled(false);
    speakButton.setText("Recognizer not present");
    }
    }

    /**
    * Handle the click on the start recognition button.
    */
    public void onClick(View v) {
    if (v.getId() == R.id.btn_speak) {
    startVoiceRecognitionActivity();
    }
    }

    /**
    * Fire an intent to start the speech recognition activity.
    */
    private void startVoiceRecognitionActivity() {
    Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
    intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
    RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
    intent.putExtra(RecognizerIntent.EXTRA_PROMPT, "Speech recognition demo");
    startActivityForResult(intent, VOICE_RECOGNITION_REQUEST_CODE);
    }

    /**
    * Handle the results from the recognition activity.
    */
    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == VOICE_RECOGNITION_REQUEST_CODE && resultCode == RESULT_OK) {
    // Fill the list view with the strings the recognizer thought it could have heard
    ArrayList<String> matches = data.getStringArrayListExtra(
    RecognizerIntent.EXTRA_RESULTS);
    mList.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1,
    matches));
    }

    super.onActivityResult(requestCode, resultCode, data);



    And i have created,voice_recognition.xml in layout and made changes too...As given in the code,Araylist??should i create arraylist?/and what is simple_list_item_1??should it be created in the layout or is it present in the api??need help..:confused:
     

    Advertisement
  2. jonbonazza

    jonbonazza Well-Known Member

    Joined:
    Jul 13, 2010
    Messages:
    1,934
    Likes Received:
    458
    1) Arraylist is an object. It has nothing to do with an XML file, well, directly anyways...

    2) android.R.simple_list_item_1 is a pre-assembled layout that comes with the android SDK. Any resource preceded with android.R is an example resource that comes with the android SDK. Although you COULD just use this resource, if you plan to place it in the android market, I would highly recommend creating your own resource to use in place of it, else you will just be laughed at by other devs (no offense).
     
  3. ajith19

    ajith19 New Member This Topic's Starter

    Joined:
    Aug 22, 2010
    Messages:
    2
    Likes Received:
    0
    Then could you please tell me how to get started???want make speech to text application?
     
  4. mohitjaitly

    mohitjaitly Active Member

    Joined:
    Oct 18, 2010
    Messages:
    34
    Likes Received:
    0
    The sample from the android site works totally fine. If you download the samples from the site, you would also get the lay out xml along with it. In this particular example, they have provided a button, on clicking this button, the voice recognition activity starts up and record the speech/voice commands. Then it shows the list of the words it recognized.
    The xml -
    HTML:
    1.  
    2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    3.    android:layout_width="match_parent"
    4.    android:layout_height="match_parent"
    5.    android:orientation="vertical">
    6.    
    7.     <TextView
    8.        android:layout_width="match_parent"
    9.        android:layout_height="wrap_content"
    10.        android:paddingBottom="4dip"
    11.        android:text="Speak Up" />
    12.        
    13.     <Button android:id="@+id/btn_speak"
    14.        android:layout_width="match_parent"
    15.        android:layout_height="wrap_content"
    16.        android:text="Speak" />
    17.        
    18.     <ListView android:id="@+id/list"
    19.        android:layout_width="match_parent"
    20.        android:layout_height="0dip"
    21.        android:layout_weight="1" />
    22.  
    23.  </LinearLayout>
    24.  
     
  5. plmuthu25

    plmuthu25 New Member

    Joined:
    Oct 24, 2010
    Messages:
    2
    Likes Received:
    0
    can u explain how speech to voice works ???
     
  6. mohitjaitly

    mohitjaitly Active Member

    Joined:
    Oct 18, 2010
    Messages:
    34
    Likes Received:
    0
    I think you meant speech to text.
    So basically, as mentioned earlier, basic example is available online on android site.

    Android sdk provides Voice Recognition Activity, which we have to use. So one can code, to start this activity on some user action. You can also show a prompt to user mentioning things if you are expecting certain type of format (Example - Voice Dial in android phones. They mention there some commands/patterns they are expecting like "Call John" etc).

    This activity can be configured in various ways as well. Refer here

    The voice recognition activity, would try to recognize the voice input and return back list of stringsthat it recognized. Based on this result, we can if required confirm from user if this is what he/she meant and proceed further.

    The code mentioned above, starts this voice recognition activity on button click.
    First registering it here -
    Code (Text):
    1. speakButton.setOnClickListener(this);
    And then starting the activity here -
    Code (Text):
    1.  
    2.    public void onClick(View v) {
    3.         if (v.getId() == R.id.btn_speak) {
    4.             startVoiceRecognitionActivity();
    5.         }
    6.     }
    7.  
    8.     /**
    9.      * Fire an intent to start the speech recognition activity.
    10.      */
    11.     private void startVoiceRecognitionActivity() {
    12.         Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
    13.         intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
    14.                 RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
    15.         intent.putExtra(RecognizerIntent.EXTRA_PROMPT, "Speech recognition demo");
    16.         startActivityForResult(intent, VOICE_RECOGNITION_REQUEST_CODE);
    17.     }
    Then as the voice input is recognized, the result comes back -
    Code (Text):
    1.  
    2. protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    3.         if (requestCode == VOICE_RECOGNITION_REQUEST_CODE && resultCode == RESULT_OK) {
    4.             // Fill the list view with the strings the recognizer thought it could have heard
    5.             ArrayList<String> matches = data.getStringArrayListExtra(
    6.                     RecognizerIntent.EXTRA_RESULTS);
    7.             mList.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1,
    8.                     matches));
    9.         }
    10.  
    11.         super.onActivityResult(requestCode, resultCode, data);
    12.     }
    Its just that in this example, they are collecting all the recognized strings in a list and displaying in a ListView on the screen. You would be getting back the string/text and this can be used further in any way you want !!
    Code (Text):
    1. data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
     
  7. Gary_12

    Gary_12 New Member

    Joined:
    Mar 4, 2011
    Messages:
    1
    Likes Received:
    0
  8. deepthycimat

    deepthycimat New Member

    Joined:
    Mar 19, 2011
    Messages:
    1
    Likes Received:
    0
    Hi i am new to android development. now i am trying for speech to text conversion and i get the code from this site. but while implementing this am always getting recognizer not present message. i am connected my system with microphone. can anyone help me. i am trying this for past 2 weeks.


    Thank you in advance...
     
  9. SunilKumar69

    SunilKumar69 New Member

    Joined:
    Jul 7, 2011
    Messages:
    1
    Likes Received:
    0
    Could u please tell me how to recognize the french speech
     
  10. skrappykoko00

    skrappykoko00 New Member

    Joined:
    Jul 12, 2011
    Messages:
    3
    Likes Received:
    0
    hi sir..i newbie for making android apps..but my thesis is i will make an android apps that converts voice to text/sms and i want to add our language "FILIPINO" can you give me some tutorials or guide on how will i start..im using eclipse


    kindly add me on my facebook..

    akoposi28@yahoo.com.ph
     
  11. droidAdvance

    droidAdvance New Member

    Joined:
    Dec 20, 2011
    Messages:
    1
    Likes Received:
    0
    Hi,

    Recently i'm developing an app with the assist of Google's speech to text API. However, the speech to text screen is always displayed at the top left of the tablet screen. Is there any method to set the speech to text screen position? Is it possible to set it at the middle of tablet screen?
     

Share This Page

Loading...