Wednesday, December 21, 2011

Android TextToSpeech

Android TextToSpeech:

this example for text convert speech. ex: what you are passing value into texttospeech it convert speech.
android text to speech example code ;

Emulator this is working fine but mobile you have install external library speech synthesis..... form android android market.

Goto->mobile->settings->voice input and output->text-to-speech settings->install voice data.


public class TextToSpeachActivity extends Activity implements OnInitListener {
    /** Called when the activity is first created. */
    private TextToSpeech    textToSpeech;;
    EditText edt;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
         edt=(EditText)findViewById(R.id.edittext);
        Button btn =(Button)findViewById(R.id.button1);
        textToSpeech=new TextToSpeech(this, this);
      //  textToSpeech.setLanguage(Locale.US);
        btn.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                textToSpeech.speak(edt.getText().toString(), TextToSpeech.SUCCESS, null);
            }
        });
    }
    @Override
    public void onDestroy() {
        if (textToSpeech != null) {
            textToSpeech.stop();
            textToSpeech.shutdown();
        }
        super.onDestroy();
    }
    public void onInit(int status) {
    }
}

Check out this may be help you

Related Posts Plugin for WordPress, Blogger...