1.问题描述:
项目需要做一个随音乐节奏律动的动效,需要获取正在播放歌曲的律动信息,也就是一个随音乐节奏变化的值。
2.尝试解决办法:
1.目前找到的结果是需要使用 AVAudioPlayer 播放该歌曲时才能获取到该音频的律动能量值,对应接口如下:
/* returns peak power in decibels for a given channel */
- (float)peakPowerForChannel:(NSUInteger)channelNumber;
/* returns average power in decibels for a given channel */
- (float)averagePowerForChannel:(NSUInteger)channelNumber;
2.尝试使用录音的方式,将手机播放的音频录起来,然后再获取这些音频的能量值。但是受到周围噪声干扰很大,效果很不好,不知道是不是我处理方式不对。
3.未解决问题:
项目需要的做到的效果是:无论任何播放源,例如使用酷狗播放器、QQ音乐播放器、网易云音乐等,都要能获取到手机输出音频的律动信息。
假如你有任何头绪或者建议,请务必告知我一下,非常感谢!
It is not particularly convenient to answer on the mobile phone. I recommend Baidu: "websocket and audio", which should have the answer you want.
I also encountered this problem today, have you solved it?
AVAudioPlayer has a method
updateMeters()
You can try adjusting this method first and then the above two. This is how I get the sound volume when recordingAnd you have to pay attention to the volume~~I remember it is negative, such as peak = - 80 this kind