I'm working on editing Mespeak.js to help out a friend with visual tracking problems.
I've been looking through Mespeak.js ( http://www.masswerk.at/mespeak/) and trying to figure out how to grab each word as it is spoken, and then display it on the screen while the wav file is playing.
I'm thinking this has to do with returning the data as an array, and then displaying the array as the wav plays. I'm not even sure this is possible (or what the raw data looks like).
Here's what I have
div id="display">
<span>Here.</span>
</div>
<script type="text/javascript">
var timeoutID
var texttosend = prompt('Text to Split');
var res = texttosend.split(" ")
var arrayLength = res.length;
function refresh(word) {
meSpeak.speak(res[i], {speed: 100});
console.log(res[i]);
$( "#display span" ).text(word);
};
console.log('here');
for (var i = 0; i <= arrayLength; i++) {
timoutID = window.setTimeout(refresh(res[i]), 50000+(i*50000));
};
There are two problems here - I think they are both related to the delay. No matter what I set the timeoutID to the text is snythesized all at once and the only word displayed is the last one. I've tried using variations of setTimeout and I've tried jQuery's delay. Any ideas on how to help? The console.log outputs each word separately, so I know the separation of text into an array works and the loop works - I think it's now just timing.
Sorry if this doesn't make a ton of sense - I guess some clarity would help me start to dismantle this problem.