Untitled
unknown
python
4 months ago
970 B
2
Indexable
def calc_dB(files, start=10, stop=-1): power = [] duration = [] error = 0 for file in files: audio = AudioSegment.from_file(file) y = audio.get_array_of_samples() sr = int(len(y)/audio.duration_seconds) if stop == -1: timediff = audio.duration_seconds -1 - start else: timediff = stop - start duration.append(timediff) integrated_power = np.sum((np.array(y[sr*start:sr*stop]).astype(np.int32))**2/65535) power.append(10*np.log10( integrated_power / timediff )) # --------------------------------------------------------------- # Added this s_p_j2 = np.sum(( 0.05 * 2 * (np.array(y[sr*start:sr*stop]).astype(np.int32))**2 /65535 )**2) s_p_j2dB = 10/integrated_power*s_p_j2 error += s_p_j2dB # --------------------------------------------------------------- print('Error: ', s_p_j2dB) return [np.array(power), error]
Editor is loading...
Leave a Comment