def is_periodic(aud_sample, SAMPLING_RATE = 8000):
'''
:param aud_sample: Numpy 1D array rep of audio sample
:param SAMPLING_RATE: Used to focus on human speech freq range
:return: True if periodic, False if aperiodic
'''
threshold = 20
# Use auto-correlation to find if there is enough periodicity in [50-400] Hz range
values = signal.correlate(aud_sample, aud_sample, mode='full')
# [50-400 Hz] corresponds to [2.5-20] ms OR [20-160] samples for 8 KHz sampling rate
l_idx = int(SAMPLING_RATE*2.5/1000)
r_idx = int(SAMPLING_RATE*20/1000)
values = values[len(values)/2:]
subset_values = values[l_idx:r_idx]
if np.argmax(subset_values) < threshold:
return False
else:
return True
评论列表
文章目录