Confusion with meters in AVAudioRecorder

浪子不回头ぞ 提交于 2019-12-10 16:53:46

问题


Simply put, I'm trying to lip-sync something based on the decibel reading from the mic input stream of an iPhone, and the values I'm getting aren't quite what I'm after. I'm using AVAudioRecorder's peakPowerForChannel and averagePowerForChannel. (I'm aware that this is a rather simplistic lip-sync technique, but quality isn't a major concern).

When the number of decibels increases, the meters react as I'd like them to (higher value when louder, so I can map this to the open-ness of the mouth) but when the sound stops quickly, the values decrease slowly, as though the sound was trailing off (i.e. fading to silence over a second or two) - not what I'd like.

Is there a way of configuring the AVAudioRecorder so that it doesn't have this 'fade' effect, or can I do something with the values that it gives me to get the desired output? Alternatively, is there another tool I can use?

Thanks!


回答1:


The meter ballistics on AVAudioPlayer are what you'd expect for displaying traditional audio meters: Instantaneous for increases in amplitude, but lowpassed for decreases.

For the Talking Carl-type thing where you animate a character based on recorded audio you'll have to get at the raw audio and tweak your own metering response as appropriate. If you're animating the character live (i.e., while the user talks in the device's microphone) you'll probably want to use AudioQueue or RemoteIO to get at the audio data. Otherwise, if you're just processing an audio file after it's been recorded, you can get the data you need using ExtAudioFile.




回答2:


You can reset the meteringEnabled property to YES, like this:

yourRecorderName.meteringEnabled = YES

Call this every time you want the levels to reset to ambient levels. This takes about 0.02 seconds, and in that time the levels will briefly drop down to 0, or -120 dB before resetting to ambient.

Alternatively, you can use:

[yourRecorderName stop]
[yourRecorderName record]

This takes about 0.05 seconds, but the levels won't drop down to 0 in the wait time. In fact, nothing will happen because in this case, it actually takes the recorder object 0.05 seconds to stop and start recording again.



来源:https://stackoverflow.com/questions/5689774/confusion-with-meters-in-avaudiorecorder

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!