Emphasize an effect for text and / or images that looks like sync with audio
I am looking at how to approach the following problem:
We have an application that displays text with sound recordings. For this we use Browser Control (Internet Explorer) in a Delphi application. We respond to events in the Delphi innerHTML code setting for elements if we need to update the style ...
The query should now add a parameter to dynamically move the cursor or dynamically highlight the words specified in the paragraph. It doesn't have to match the absolutely exact spoken word, so we'll have to dynamically update the content of the position of the highlighted word based on some kind of timer or something (because it's not text to speak).
What should be the most practical and easy approach to this problem, all the answers are greatly appreciated.
Thanks.
a source to share
suppose you have a text file with text to be displayed and an annotated time when it lights up (kind of subtitle file like the standard w3c timed text clause ( http://www.w3.org/AudioVideo/TT/ ) or the SUB - Movie subtitle file format used by several media players.
Your program must first read and parse the text file and decode the annotated time. Paste it into a string list called Subtitles, where the items will also contain objects similar to this
type tSubtitle = class
num : integer;
prevTime, fromTime : tdatetime;
toTime, nextTime: tdatetime;
text: string;
end;
You might want to expand the object to preserve some of the selection attributes.
Then you just need to display those objects synchronized with the timer.
procedure TForm1.Timer1Timer(Sender: TObject);
var rt : TDateTime;
done:boolean;
si,st,sb:integer;
s:string;
begin
rt:=now-startTime;
st:=0;
sb:=subtitles.Count; // binary search the subtitle for the current time
repeat
si:=(st+sb) div 2;
s:=TSubtitle(subtitles.Objects[si-1]);
done:= ((t>=s.prevTime) and (t<=s.nextTime));
if not done then
begin
if t>s.prevTime then st:=si
else if t<s.nextTime then sb:=si;
if st=sb then done:=true;
end;
until done;
// do what you want with s
end;
a source to share