Count frequency instances in Audio (wav) Python

Viewed 38

I am working on a function that returns the ratio of audible/non-audible frequencies in a wav file using python. I am also working on another function to give a speech/non-speech ratio. I am trying to do this based on the frequencies detected. Taking the scenario of the first function, I just want to return how much of the audio is audible (20hz-20khz). For now, I was able to get the array of frequencies in the audio and check if there are non-audible parts.

from scipy.io import wavfile
import numpy as np

wav_path = '/path/to/wav/file'

rate, wav_data = wavfile.read(wav_path, 'rb')

FFT_data = np.fft.rfft(wav_data)

freq = np.fft.rfftfreq(len(wav_data), d=1./rate)

ultrasonic = (np.where(freq > 20.E3))

infrasonic = (np.where(freq < 20))

After this, I am looking at how to get the ratio of how much the ultrasonic and infrared. Could (len(ultrasonic)+len(infrasonic))/len(freq)) work? Because I am not sure that the length of the frequencies array is relevant. I am looking to have a time-domain ratio like 2s out of 5s are audible.

0 Answers
Related