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:
- Create a New Android Studio project name SpeechtoText.
- Select minimum API level 14 so it will run Maximum of Android device that are Active on google Play then click next.
- Select Blank Activity and your Activity name is MainActivity click next > click finish.
- 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;
}
}
}
}
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"
/>
<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"
/>

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?
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...
this code are not work properly...

Admin:
what problem you have find?
what problem you have find?
Subscribe Latest Information
Categories
Most Popular Posts
How to Withdraw Money from ATM Machine 7steps 1182374 Views
How to Create Chat Application in Android Studio 152899 Views
How to Create a Shopping Cart Application in Android 116235 Views
You May Like Also
Android Floating Action Button tutorial 5702 Views
Android Material Design Snackbar tutorial 4940 Views
How to Animate your Android App 8805 Views
How to Use GoogleMap API v3 in Android 10188 Views
How to Create Overflow Menus in Android 14804 Views