简体   繁体   中英

Best way for convert speech to Pronunciation

I want to build an Android application which recognizes speech and converts it to Pronunciation text (ie 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.

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>

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

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM