简体   繁体   中英

iPhone - Question about handling duration

I'm working on some app which has text narrated by speech as well which is working fine. (Text and audio are static files) I want to high light the word according to audio. I'm able to write the code to highlight word as well.

I've starting and ending duration of the words. Like if the text is "Hi How are you", From the audio duration, for Hi - start is 0.132 and end is 2.43, How - start is 3.45 and end is 4.72, are - start is 5.29 and end is 6.05 and so on..

So, what I've to do is highlight the word "Hi" at 0.132 seconds after the start of audio and make it normal at 2.43 seconds.

I don't know how can I implement NSTimer to handle this situation. Is my thinking correct or I've to follow some other code?

Can some one guide me on how to do implement this?

It depends on how much accuracy you want to time your highlighting. Apple state in its Timer Programming Topics , the effective resolution of the time interval for a timer is limited to on the order of 50-100 milliseconds .

So what I can think of, if the accuracy is enough for your case, you can start the highlight, restart timer, setup a firing event after x seconds, when it fires, turn of the highlighting and go to the next word.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM