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);
}
}
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With