Advertisement
Guest User

Untitled

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