直接上代码吧
//second 几秒内下降为0 - (void)reduceVolume:(int)second { KGVoicePlayer *player = [KGVoicePlayer defaultPlayer]; if (!_flag) { _tempVolume = player.volume; _flag = YES; } // 经测试-45db已经可以当作静音 player.volume = dBToLinear(-4.5*(10 - second)); } static const float M_LN = 2.30258509299404568402; /* natural log of 10 */ static inline float dBToLinear( int dB ) { return exp( ( dB ) * M_LN * 0.05 ); }