Automatic voice recording when voice starts and playback when voice stops


Can anyone help me for the following :

Record voice automatically and play when silent for sometime like talking tom. Can anyone help me to identify the logic behind talking tom. When the user starts to speak, it should record automatically and when the user stops speaking, then the recorded voice should be playback. How this can be do? Please help me.

Thanks in advance

float peakPowerForChannel = pow(10, (0.05 * [soundRecorder peakPowerForChannel:0]));
float averagePowerForChannel = pow(10, (0.05 * [soundRecorder averagePowerForChannel:0]));
lowPassResults = ALPHA * peakPowerForChannel + (1.0 - ALPHA) * lowPassResults;
averagePassResults = ALPHA * averagePowerForChannel + (1.0 - ALPHA) * averagePassResults;

if (peakPowerForChannel > 0.08f) {
    [soundRecorder recordForDuration:5];
} else {
    NSLog(@"not audible");