-
Closed Captioning problem and guidance
Like most people posting for the first time here, I have no experience with javascript and need some help.
However, I found something that is almost exactly what I need. Almost isn’t close enough and I’m probably going to have to figure out the changes to make it work. Before I ask for help on that, I gave myself a crash course on javascript (give a fish v. teach to fish, etc.)
So before I go hat in hand with what I don’t know, can I get some help on whether I have correctly deciphered what’s going on in the following expression (which I pulled from a tutorial I found on youtube about using the voice recognition within CS to automate subtitling/closed captions).
L = thisComp.layer("stack_01.aif");
max = effect("words")("Slider");
n = 0;
if (L.marker.numKeys > 0){
n = L.marker.nearestKey(time).index;
if (L.marker.key(n).time > time){
n--;
}
}
s = "";
if (n > 0){
base = Math.floor((n-1)/max)*max + 1;
for (i = base; i < base + max; i++){
if (i <= L.marker.numKeys){
s += L.marker.key(i).comment + " ";
}
}
}
s
The first three lines are just defining variables and setting their values (I changed ‘max’ from the original code and hooked it up to a slider called “words”)
The first conditional statement checks to see if the total number of markers on layer L is greater than 0. It is, so n is then assigned the value (the index number) of the nearest marker. If the time value of the nth marker is greater than the current time, subtract 1 from n.
At the second loop, n = 0 to start. So we just place s (which is currently nothing, (s = “”)) into the comp. Next time back through, we are looking at the value for “max”, looping through and placing the comment (which is the subtitle text) in that many markers into the composition.
So if I have my slider set to 20, I am getting 20 words. Which I am. Again, the above code works, I’m just making sure I understand what’s happening. So I still have two questions.
1) The first conditional loop, I’ve seen it in a handful of expressions. While I can decipher it line by line, what’s the logic behind it? Is it just saying, find the number of the next marker then subtract 1 from that number?
2) What I ultimately need is subtitle text that fills a box of a certain size (so instead of just 20 words, or whatever I set the slider value to). The problem with the above is sometimes 20 words is 3 lines, sometimes it barely makes it to line 3, sometimes it pushed to 4 lines (I’m using a text box, so it fills to the width of the box, before making a carriage return).
What the client needs wants is to fill three full lines (pretty much, it won’t be justified on both margins). What attributes and methods should I be looking at? I combed through the Adobe reference guide but didn’t see anything that was obviously helpful.
Logically what I’m thinking is that I’ll just run a loop for each line. So if I want three lines, I loop it three times, but each line needs to be a certain length (as in a x-distance) and not a set number of words. Or is there a more elegant way?
Thanks for any help.