[comp.lang.objective-c] sound-text synchronizing

jrscs@uno.edu (12/18/90)

   I am working on a text-to-speech conversion program on the NeXT computer
system using Interface Builder.  Everything is coming along fine except for
one problem I hope someone can help me with.  I am having difficulty
synchronizing the highlighting of a word in a window with actually saying
the word.  As of now, the relevant code looks like the following:


- readReaderFile
{
  char  aWord[ 50 ];
  int   startPos = 0 ,
        endPos;

  while ( [ self getWordBoundaries:&startPos :&endPos ] == YES )
  {
    [ [ theDocument docView ] setSel:startPos :endPos ];
    [ [ theDocument docView ] getSubstring:aWord start:startPos length:....];
    speak( aWord , endPos - startPos );
    startPos = endPos + 1;
  }

  return self;
}

*** NOTE : The text is contained in a ScrollView's docView, hence the
           "[ theDocument docView ]" calls.

For a short file, what happens is all of the words are spoken first and then
the selections are executed.  If I put the "[ .... setSel .... ]" line in a
loop to execute about ten times, then two words are spoken and one is high-
lighted, two are spoken and one is highlighted, ....  There must be a way
around this problem.  I think a solution might entail using delegates and the
methods "willPlay" and "didPlay" for the sound object which stores the sound
data for the words in the window, but I just can't seem to hook things
together.  Can someone please give me an idea on how I can solve this problem.

Thanks,
John Stelly

wiml@milton.u.washington.edu (William Lewis) (12/19/90)

In article <009415D9.95ACE680@uno.edu> jrscs@uno.edu writes:
>one problem I hope someone can help me with.  I am having difficulty
>synchronizing the highlighting of a word in a window with actually saying
>the word.  As of now, the relevant code looks like the following:

  On a first look, it seems as if the problem is that the Window Server
(which actually *does* the drawing for all processes) is a separate
process. When you call [ text setSel ], it just sends the PostScript
code to the WS to do the drawing. The WS might not get around to executing
your code for a little while. As a result, you send off the code to the
window server, then immediately play the sound, and then send some
more code, which probably just gets put in the queue. Try using the
NXPing() function right before you play the sound: this function 
just blocks until your application's context is caught up on the sent
code (presumably meaning that the selection is actually highlighted on the
screen). As far as I know, there is very little delay for sounds (unless
your sound gets put in a queue behind someone else's, or another of
your own...)
  I'd continue, but it's starting to lightning here.

  Followups redirected to comp.sys.next.


-- 
 wiml@milton.acs.washington.edu       Seattle, Washington   
     (William Lewis)   |  47 41' 15" N   122 42' 58" W  
"These 2 cents will cost the net thousands upon thousands of 
dollars to send everywhere. Are you sure you want to do this?"