对于 iPhone 上的类似卡拉 OK 的应用程序,我应该如何对带有音频的文本突出显示进行计时?
举例来说,我有一个应用程序可以显示歌词块,一次显示 3 或 4 行。现在,我想触发一个音频文件开始播放,然后用音频本身来计时歌词的突出显示。有点像从一个单词弹到另一个单词的弹球。
我唯一能想到的是,我需要创建元数据来与每个音频文件一起使用,以便我可以启动一个与音频文件一起运行的计时器。或者也许 iOS 中的音频播放器可以公开其自己的运行计时器,并且我可以触发突出显示的单词在某些点发生变化?
知道最好的方法吗?我认为如果我必须每秒检查这个词是否应该改变,这可能会对处理器造成负担,但我不知道如何才能触发它。
Say for example I had an application that would show chunks of lyrics, 3 or 4 lines at a time. Now, I want to trigger an audio file to start playing, and then time the highlighting of the lyrics with the audio itself. Kind of like the bouncing ball that bounces from one word to another.
The only thing I can think of is that I will need to create metadata to go along with each audio file, so that I can start a timer that runs alongside the audio file. Or perhaps the audio player in iOS can expose its own running timer and I could trigger the highlighted word to change at certain points?
Any idea the best way to do this? I would think that it could be taxing on the processor if I had to check every second if the word should change, but I don't know how I could trigger it otherwise.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这不是我所知道的最佳答案,但 WWDC 2011 视频中使用 Core Animation 讨论了一个非常相似的解决方案。
找到名为 Core Animation Essentials 的视频(应该是 iTunes U 上 WWDC 2011 的视频 421)。该示例应该在第 29 分钟左右。基本上,场景是有一个球在正在播放的歌曲歌词上弹跳。该项目讨论了如何使用一个有趣的想法对单词的时间和位置进行动画处理...
尽管设计需要一点时间,但可以使用 NSTimer 和同时开始的歌曲来实现一个项目。实现该项目,以便每次按下屏幕时,上一个时间间隔的偏移量都会插入到 NSMutableSArray 中,然后写入到文件中。现在,运行该项目并在唱出每个单词时按下 为单词创建时间戳。 (这假设您事先已经知道要执行什么歌曲并且歌唱速度不太激烈)。好的...现在您有了元数据。
我建议首先尝试弹跳球,因为已经描述了实现,我发现您尝试实现的内容存在一些问题。最值得注意的是,(我可能是错的),但我不认为 UIlabel/NSString 有任何方法来突出显示子字符串。这意味着您可能必须为每个单词制作一个标签,这可能会变得非常乏味......所以请观看该视频,希望您能从中得到一些东西。祝你好运!
Not the best answer I know, but a very similar solution was discussed in one of the WWDC 2011 videos using Core Animation.
Find the video named Core Animation Essentials (should be video 421 on iTunes U for WWDC 2011). The example should be around minute 29. Basically the scenario was that there was a ball bouncing over lyrics that was being played to a song. The project talks about how to animate to the timing and position over the words using an interesting idea...
Although it would take a little bit to design, implement a project with an NSTimer and your song starting at the same time. Implement the project so every time you press on the screen, an offset from the last time interval is inserted into an NSMutableSArray, which is then written to a file. Now, run the project and make timestamps for the words by pressing down when each word is sung. (This assumes that you already know what songs you are going to implement beforehand and the singing speed is not too intense). Ok... now you have your metadata.
I would recommend trying the bouncing ball thing first because the implementation is already described as well I see a couple of problems with what you are trying to implement. Most notably, (I might be mistaken), but I don't think UIlabel/NSString has any methods to highlight substrings. Meaning you might have to make a label for each individual word which could get really tedious... So check out that video and hopefully you can get something out of that. Good Luck!
我会选择元数据选项,因为我不知道识别歌手何时改变歌词有多容易。 (即 scrapo、sting 等)
请注意,您实际上可以在主线程上调度一个函数;您不必检查该词是否已更改。您可以使用:
我不完全确定内存问题,但我用它来播放我的应用程序中录制的 midi 文件。我只是根据元数据安排changeWord 函数。
至于制作元数据,我不确定除了暴力之外还可以使用什么方法。必须有一些预先写好的元数据;毕竟还有其他卡拉 OK 应用程序。
I would go with the metadata option, since I don't know how easy it would be to, say, recognize when the singer changes words. (i.e. screamo, sting, etc.)
Note that you can actually schedule a function on the main thread; you don't have to check whether or not the word has changed. You can use:
I'm not entirely certain as to the memory issues, but I use it to play back recorded midi files in my app. I'd simply schedule the changeWord function based on the metaData.
As for making the metaData, I'm not sure what method you could use other than brute force. There must be some prewritten metaData; after all, there are other karaoke apps.