Like Us on Facebook

How to make Speech to Text conversion Apps in Android

Hi , As per the request  today I am going to share how to  convert a  speech  to Text  in Android application. The utility of this Application is  to take  voice input  and convert it  into a text  format. You need clear concept how the Application works. Let checkout how to do it.


Prerequisites:
 
  • JDK 6.0 or above
  • Android Studio


Steps to follow:  
 
  1. Create a New Android Studio project name  SpeechtoText.
  2. Select minimum  API level 14 so it will run Maximum of Android device that are Active on google Play then click next.
  3. Select Blank Activity and your Activity name is MainActivity click next > click finish.
  4. Inside MainActivity Class write the following code:
 
 public class MainActivity extends Activity {

 protected static final int SPEECH =1;
 private ImageButton speak;
 private TextView txt;
/** Called when the activity is first created. */
@Override
 public void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 setContentView(R.layout.main);
 txt = (TextView)findViewById(R.id.txtText);
 speak =(ImageButton)findViewById(R.id.speakbtn);
 speak.setOnClickListener(new View.OnClickListener() {
 
 @Override
  public void onClick(View v) {
  // TODO Auto-generated method stub
  
Intent in = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
  in.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, "en-us");
 
  try{

  startActivityForResult(in, SPEECH);
  txt.setText("");

  }catch(ActivityNotFoundException e){
                 
 Toast t = Toast.makeText(getApplicationContext(),"your device not suppot Speech to Text",Toast.LENGTH_SHORT); 
                 
                  t.show();
  }
  }
  });
   }
  /* (non-Javadoc)
 * @see android.app.Activity#onCreateOptionsMenu(android.view.Menu)
  */
  
@Override
  public boolean onCreateOptionsMenu(Menu menu) {
   // TODO Auto-generated method stub
   
getMenuInflater().inflate(R.menu.main, menu);
    return true;
   }
   /* (non-Javadoc)
    * @see android.app.Activity#onActivityResult(int, int, android.content.Intent)
    */
  
@Override
   protected void onActivityResult(int requestCode, int resultCode, Intent data) {
      // TODO Auto-generated method stub
   
super.onActivityResult(requestCode, resultCode, data);
   switch(requestCode){
   case SPEECH: {
          
  if(requestCode== RESULT_OK && null!= data)
  {
  ArrayList<String> text = data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
   txt.setText(text.get(0));
  }
    break;
 }
 }
 }
 }
 


 5.and your main.xml file  of res folder is look like
 
<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 
android:layout_width="fill_parent"
 
android:layout_height="wrap_content"
 
android:gravity="center"
 
android:orientation="vertical" >

<ImageButton
android:id="@+id/speakbtn"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="12dp"
android:layout_marginRight="12dp"
android:contentDescription="@string/speak"
android:src="@android:drawable/ic_btn_speak_now"
/>

<TextView
android:id="@+id/txtText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:textAppearance="?android:attr/textAppearanceLarge"
/>

Posted By UandBlog

UandBlog is a Global Leading source of Finance, Health, Lifestyle, Technology, Gaming and Programing and other information, it is a fastest growing blog for all , for latest post or information like us on facebook , follow on Twitter, Google+ and Pinterest.

Comments ( 2 )

Jude Pureza:
Ito na po ba lahat ng code at kapag sinunnod ko lahat ng steps na kelangan para magawa yung speech convert to txt gamit po android phone ay pwede na pang thesis? at gagana po sya?
Admin:
kuldip kotadiya:
this code are not work properly...
Admin:
what problem you have find?

    Leave a comment..

    Click to login.

    Subscribe Latest Information

    Most Popular Posts

    You May Like Also