16

I want to build an Android application which recognizes speech and converts it to Pronunciation text (i.e to compare true Pronunciation or accent between special word and user speech). I just know it's possible to create speech to text. I want to convert any words that user say.

Is there any API to do it? If not, please help me how to implement it.

unor
  • 92,415
  • 26
  • 211
  • 360
hojjat reyhane
  • 648
  • 1
  • 8
  • 25

3 Answers3

2

I just give a code for speech to text . It Is a demo. I don't know this will help you. But i am using this for my application. Try To use it.

SpeechtoText.java

public class SpeechtoText extends Activity {
protected static final int RESULT_SPEECH = 1;
private ImageButton btnSpeak;
private TextView txtText;
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    txtText = (TextView) findViewById(R.id.txtText);
    btnSpeak = (ImageButton) findViewById(R.id.btnSpeak);
    btnSpeak.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent intent = new Intent(
                    RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
            intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, "en-US");
            try {
                startActivityForResult(intent, RESULT_SPEECH);
                txtText.setText("");
            } catch (ActivityNotFoundException a) {
                Toast t = Toast.makeText(getApplicationContext(),
                        "Ops! Your device doesn't support Speech to Text",
                        Toast.LENGTH_SHORT);
                t.show();
            }
        }
       });
   }
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.activity_main, menu);
    return true;
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    switch (requestCode) {
    case RESULT_SPEECH: {
        if (resultCode == RESULT_OK && null != data) {
            ArrayList<String> text = data
                    .getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
            txtText.setText(text.get(0));
        }
        break;
    }
    }
}

}

activity_main.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/textView1"
android:layout_toLeftOf="@+id/textView1"
android:gravity="center"
android:orientation="vertical" >
<ImageButton
    android:id="@+id/btnSpeak"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_margin="10dp"
    android:layout_marginRight="10dp"
    android:layout_marginTop="10dp"
    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>
user3506595
  • 129
  • 11
0

These libraries might work for you. I personally have not used them in Android, but they are packages for Java.

Check out this answer: https://stackoverflow.com/a/9055291/3662013

Community
  • 1
  • 1
krodmannix
  • 845
  • 10
  • 30
0

Android has a native way to provide developers speech recognition using the SpeechRecognizer class.

This answer has a very good explanation of the pros and cons of using this API:

Offline Speech Recognition In Android (JellyBean)

Community
  • 1
  • 1
peguerosdc
  • 946
  • 11
  • 21