Saturday, 15 June 2019

Android TextToSpeech

Android Text to Speech is the speech the text which ever you want.

below is the code for Text to speech. 


public class MainActivity extends AppCompatActivity implements TextToSpeech.OnInitListener{
TextToSpeech textToSpeech;
@Override protected void onCreate(Bundle savedInstanceState) {     super.onCreate(savedInstanceState);     setContentView(R.layout.activity_main);
    textToSpeech = new TextToSpeech(mcontext, MainActivity.this);
TextToSpeechFunction();
}
public void TextToSpeechFunction() {     String textholder = "Test the TextToSpeech";
    textToSpeech.speak(textholder, TextToSpeech.QUEUE_FLUSH, null);   //  Toast.makeText(MainActivity.this , textholder, Toast.LENGTH_LONG).show(); } @Override public void onDestroy() {     textToSpeech.shutdown();     super.onDestroy(); } public void onInit(int Text2SpeechCurrentStatus) {     if (Text2SpeechCurrentStatus == TextToSpeech.SUCCESS) {         textToSpeech.setLanguage(Locale.US);         TextToSpeechFunction();     } }
}

Snackbar in Kotlin

How to show snackbar in place of toast message , below is the code for showing snackbar in kotlin. Below code is put in Utils.kt  (common fi...