Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

Highlight words as audio plays

I'm trying to highlight text on a page as an audio clip of that text is read to the reader.

Any ideas? I found the kitchen sink examples of playing/stopping/etc sound but can't figure out how to sync it with highlighting of text.

— asked May 21st 2010 by Kelly Redd
  • highlighting
  • sound
0 Comments

2 Answers

  • You could use setInterval to check the current position of the sound ( Sound.getTime ),and based on this to modify the background of the correspondent word ( each word being a label )

    Or you could use audioPlayer that has a progress event triggered at 1s intervals.

    — answered May 21st 2010 by Dan Tamas
    permalink
    0 Comments
  • Thanks Tamas, great ideas and I'll keep them in mind. I'm not sure what solution i'll end up using at the moment. Still familiarizing myself with all the sound functionality available.

    Right now I just play the sound with a button click and if sound is playing fire a highlight function using setInteval.

    Posting my code for the sake of maybe helping others….

    function hiText(page)
    {   
        c = 0;
        l = page.children[0].children.length;
        var t = setInterval(function()
        {
            page.children[0].children[c].backgroundColor = 'yellow';
            c++;
    
            // stop when we run out of words
            if(c>=l)
            {
                clearInterval(t);
            }
    
        },[1000]);
    
    }
    
    page1_play.addEventListener('click', function()
    {
        page1_sound.play();
    
        if (page1_sound.isPlaying())
        {
            hiText(page1);
        }
    });
    
    — answered May 22nd 2010 by Kelly Redd
    permalink
    0 Comments
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.