Advertisement
Guest User

Untitled

a guest
Mar 20th, 2019
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.31 KB | None | 0 0
  1. import android.app.Activity;
  2. import android.os.Bundle;
  3. import android.speech.tts.TextToSpeech;
  4. import android.view.View;
  5. import android.widget.Button;
  6. import android.widget.EditText;
  7. import java.util.Locale;
  8. import android.widget.Toast;
  9.  
  10. public class MainActivity extends Activity {
  11. TextToSpeech t1;
  12. EditText ed1;
  13. Button b1;
  14.  
  15. @Override
  16. protected void onCreate(Bundle savedInstanceState) {
  17. super.onCreate(savedInstanceState);
  18. setContentView(R.layout.activity_main);
  19. ed1=(EditText)findViewById(R.id.editText);
  20. b1=(Button)findViewById(R.id.button);
  21.  
  22. t1=new TextToSpeech(getApplicationContext(), new TextToSpeech.OnInitListener() {
  23. @Override
  24. public void onInit(int status) {
  25. if(status != TextToSpeech.ERROR) {
  26. t1.setLanguage(Locale.UK);
  27. }
  28. }
  29. });
  30.  
  31. b1.setOnClickListener(new View.OnClickListener() {
  32. @Override
  33. public void onClick(View v) {
  34. String toSpeak = ed1.getText().toString();
  35. Toast.makeText(getApplicationContext(), toSpeak,Toast.LENGTH_SHORT).show();
  36. t1.speak(toSpeak, TextToSpeech.QUEUE_FLUSH, null);
  37. }
  38. });
  39. }
  40.  
  41. public void onPause(){
  42. if(t1 !=null){
  43. t1.stop();
  44. t1.shutdown();
  45. }
  46. super.onPause();
  47. }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement