android - String Array increment each string in TextToSpeech -
using text speech api want change string array increment index 0 string , when reaches end go beginning.
at moment uses random generator , method works follows:
public static void sayhello() { // select random hello. int hellolength = hellos.length; string hello = hellos[random.nextint(hellolength)]; mtts.speak(hello, texttospeech.queue_flush, // drop pending entries in playback queue. null); }
hellos array , holds strings:
string [] hellos = {"one" "two" "three" "four"};
appreciate thanks.
when want increment index loop around 0 again modulo friend.
int currenthelloindex = 0; public static void sayhello() { // select random hello. int hellolength = hellos.length; string hello = hellos[currenthelloindex]; currenthelloindex = (currenthelloindex + 1) % hellolength; mtts.speak(hello, texttospeech.queue_flush, // drop pending entries in playback queue. null); }
Comments
Post a Comment