Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def create_analyzers(fs=44100.0,
nhop=512,
nffts=[1024, 2048, 4096],
mel_nband=80,
mel_freqlo=27.5,
mel_freqhi=16000.0):
analyzers = []
for nfft in nffts:
window = Windowing(size=nfft, type='blackmanharris62')
spectrum = Spectrum(size=nfft)
mel = MelBands(inputSize=(nfft // 2) + 1,
numberBands=mel_nband,
lowFrequencyBound=mel_freqlo,
highFrequencyBound=mel_freqhi,
sampleRate=fs)
analyzers.append((window, spectrum, mel))
return analyzers
numBins : (integer ∈ [12, ∞), default = 12) :
the size of the output HPCP (must be a positive nonzero multiple of 12)
whitening : (boolean (True, False), default = False)
Optional step of computing spectral whitening to the output from speakPeak magnitudes
'''
audio = array(self.audio_vector)
#print audio.shape
frameGenerator = estd.FrameGenerator(audio, frameSize=frameSize, hopSize=hopSize)
window = estd.Windowing(type=windowType)
spectrum = estd.Spectrum()
# Refer http://essentia.upf.edu/documentation/reference/std_SpectralPeaks.html
spectralPeaks = estd.SpectralPeaks(magnitudeThreshold=0,
maxFrequency=maxFrequency,
minFrequency=minFrequency,
maxPeaks=maxPeaks,
orderBy="frequency",
sampleRate=self.fs)
# http://essentia.upf.edu/documentation/reference/std_SpectralWhitening.html
spectralWhitening = estd.SpectralWhitening(maxFrequency= maxFrequency,
sampleRate=self.fs)
# http://essentia.upf.edu/documentation/reference/std_HPCP.html
hpcp = estd.HPCP(sampleRate=self.fs,
maxFrequency=maxFrequency,
"""
Wrap around the essentia library to compute HPCP features
:param XAudio: A flat array of raw audio samples
:param Fs: Sample rate
:param winSize: Window size of each STFT window
:param hopSize: Hop size between STFT windows
:param squareRoot: Do square root compression?
:param NChromaBins: How many chroma bins (default 36)
:returns H: An (NChromaBins x NWindows) matrix of all
chroma windows
"""
import essentia
from essentia import Pool, array
import essentia.standard as ess
print("Getting HPCP Essentia...")
spectrum = ess.Spectrum()
window = ess.Windowing(size=winSize, type='hann')
spectralPeaks = ess.SpectralPeaks()
hpcp = ess.HPCP(size = NChromaBins)
H = []
for frame in ess.FrameGenerator(XAudio, frameSize=winSize, hopSize=hopSize, startFromZero = True):
S = spectrum(window(frame))
freqs, mags = spectralPeaks(S)
H.append(hpcp(freqs, mags))
H = np.array(H)
H = H.T
if squareRoot:
H = sqrtCompress(H)
return H
def __init__(self, frame_size, hop_size, window_type, feature,
beats, sample_rate):
"""STFTFeature constructor."""
self.frame_size = frame_size
self.hop_size = hop_size
self.window_type = window_type
self.w = ES.Windowing(type=window_type)
self.spectrum = ES.Spectrum()
self.feature = feature # Essentia feature object
self.beats = beats
self.sample_rate = sample_rate
def __init__(self, frame_size, hop_size, window_type, feature, sample_rate,
beats=None):
"""STFTFeature constructor."""
self.frame_size = frame_size
self.hop_size = hop_size
self.window_type = window_type
self.w = ES.Windowing(type=window_type)
self.spectrum = ES.Spectrum()
self.feature = feature # Essentia feature object
self.beats = beats
self.sample_rate = sample_rate