[RESOLVED] creating a uniform delay of n seconds between the sounding of two words.
hi all !
So I have another problem that I am stuck with.
I have the sound files of the following words.
pre, vent, ed, lift, seed, as
pre.mp3, vent.mp3, ed.mp3, lift.mp3 etc
and I wish to use these to make the computer to call out the following words.
prevented, lifted, seeded, preceded. So I have broken these as:
1. pre-vent-ed
2. lift-ed
3. seed-ed
4 pre-seed-ed ( This would be the same sound as preceded)
I have stored each of these words in a string which i convert into an array by exploding it before passing the array to
a pn_sound function.
The pn_sound function checks to see if all words have been called out and if not calls another function ok_sound
ok_sound takes the sound array for each word for e.g. for pre-vent-ed it would have the sounds arr[0] = pre, arr[1]=vent, arr[2] = ed.
It then creates a new sound object (s = new sound() and attaches the first sound ( arr[0] = pre) to it,
s.attachsound(arr[0]);
s.start // and plays the sound.
s.onsoundcomplete then checks to see if there are more bytes in the array to complete the sound of the word. If so it attaches the next byte and calls s.start again to play the sound thus forming a recursive function.
Thus onsoundcomplete recurses till all bytes have been played and the sound for the word completed.
Now is the time to fetch the next word and play it and so on till all words have been played.
What I want is that irrespective of the time it takes to play each word, THERE SHOULD BE A CONSTANT GAP BETWEEN ANY 2 WORDS. so
once a words has been played, the program should wait for say 3 or 4 seconds before it fetches the next word and plays it.
Please can someone show me how I can achieve this.
Please find attached the file I have been working on. I have tried to achieve a uniform delay in many ways but could not achieve it. I have tried using setInterval and setTimeOut and their combinations too. Maybe I over-tried it I guess.
So what this attached file is doing is that it generates a 2.5 sec delay and calls the words during that delay. If the word is long it takes a longer time to call out and so the gap between the calling out of two words is uneven.
I want that two words, no matter their size, should have a constant delay between their calling out.
Thanks loads for the replies. I just logged in and wow ! 3 replies from you. Thanks so much. I'll look into them tomorrow since it's very late now and revert with my implementation. I am sure that I would not need to do much since I am sure you would have done it best already.
Thanks loads for all your help. I appreciate it much.
P.S. On a lighter note, if it took you 3 times to perfect this one, I now don't mind the 15 odd different tries that I made in trying to do this right and still couldn't.
Thanks Loads, I have gone through the final version and yes it works great. That was a nice idea to add the time-delay of the word sound to delay of 2500 between words. I had thought of this but i was hoping that there was some pure wait or delay function that could be used directly which apparently there isn't. Yet I think the final version was really short and sweet.