Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how can we make our app to speak text on opening the app?

i want my app to speak "Hi! My name is Torz. How can I help you ?" whenever someone open the app. I am trying this approach but its not working for me.

public class MainActivity extends AppCompatActivity {

TextToSpeech t1;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);


    t1=new TextToSpeech(MainActivity.this, new TextToSpeech.OnInitListener() 
  {
        @Override
        public void onInit(int status) {
            if(status != TextToSpeech.ERROR) {
                t1.setLanguage(Locale.ENGLISH);
            }
        }
    });
    String b="Hi! My name is Torz. How can I help you ?";
    t1.speak(b,TextToSpeech.QUEUE_FLUSH,null);

}
}
like image 684
Wassauf Khalid Avatar asked Dec 04 '25 05:12

Wassauf Khalid


1 Answers

Add you code

 String b="Hi! My name is Torz. How can I help you ?";
 t1.speak(b,TextToSpeech.QUEUE_FLUSH,null);

In onInit method and it will work.

like image 139
Abdul Waheed Avatar answered Dec 06 '25 21:12

Abdul Waheed



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!