highlighting text as it is narrated(audio .mp3)
I'm using Cocos2d for all the animated sprite/transition stuff, but I'm not sure how to approach highlighting text as it is narrated.
Example: "Jack and Jill, drank their fill, and were too drunk to go for water." As the text is narrated (.mp3 plays on each page), the text would be highlighted.
If someone has a clue or s开发者_运维技巧ample code I'd really appreciate it.
Thanks
Shiva.I'm not sure if you can 'count' words from audio, I really don't dabble in audio on the iphone enough to give any clear advice from that angle, but if it was me, i'd do this.
It might seem a little clunky, but it seems like it would do what you want.
I would have a CCScheduler, that runs every 0.5 seconds perhaps.
I would also have an array for my audio file, perhaps saved into a plist (so multiple audio files can 'arrays' can be stored into a dictionary.
The array would hold integers, these would represent time that has elapsed since the audio started playing, objectAtIndex:0 would be the lowest number, and each one would go up from there.
You would add one for each word in your sentence or audio.
When you start your audio file playing, hold a variable to [NSDate date] (recording the exact time the audio started playing (near enough)).
In your scheduler, check [array objectAtIndex:0] against the amount of time that has elapsed since the audio started playing, if the array object is smaller, trigger a method that draws your 'highlight' behind that part of text, then [removeObjectAtIndex:0].
If objectAtIndex:0 is larger than time elapsed, simply return;
Quite how you would keep track of the words positions, perhaps drawing each one seperately as an individual CCSprite, and the highlighting method would be down to your own preference, but that's an approach I might take.
For that you need to download the .srt file which contains the lyrics, starting time and ending time for each line.
Have a look at the section labelled "The Hills are Alive, with the Sound of… Audio Files :]" in this tutorial. It shows you how to use Audacity to record your audio, label each word and export a text file that indicates when each word starts.
http://www.raywenderlich.com/19415/how-to-make-an-interactive-ebook-without-any-code
精彩评论