简体   繁体   中英

How to change the percentage according to the recorded audio volume

As shown on the below figure ( Source : Disney spot light app https://itunes.apple.com/in/app/disney-spotlight-karaoke/id455072135?mt=8 )

I want to change the percentage value, depends on recorded sound while recording audio.

if we keep the device in the quite silent places, the peracentage not to be changed..

If we keep the device at a full loudly place, song/ voice / machine sound or any sound.. the percentage needs to be increase according to the volume recorded.

How can we do it in iOS using objective c

在此处输入图片说明

Supposing you're using an AVAudioRecorder to record your sounds, you can call:

[audioRecorder setMeteringEnabled:YES];

before starting to record in order to enable the audio-level metering. Then at any time you can call:

[audioRecorder updateMeters];
float audioPower = [audioRecorder averagePowerForChannel:0]; // You can change 0 according to your input channels

audioPower will give you a float value between -160 and 0 dB, that you then can adapt to your needs.

If you want to constantly poll the audio level you can call the code above through an NSTimer action or use an NSOperationQueue

Check AVAudioRecorder reference for more details on these methods

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