I'm working on audio analysis project, my input audio y
has been converted to audio vectors, output of y
:
array([-0.00085973, -0.00062583, -0.00042983, ..., 0.00038916,
0.00024691, 0.00010018], dtype=float32)
I have used those parameters for detection: Signal length =357454, Sampling Rate= 44100, Hop size=512, Frame size=2048
I used the librosa.autocorrelation
for pitch detection but it gave me the correlation for whole input signal.
I tried to segment my input signal and get the pitch, I got the following error:
signal=y1
sampleRate = 44100
frameSize = 2048
hop = 512
length=len(y1)
pitch = []
start, stop = 0, 512
while stop <= length:
f0 = y1[start:stop]
autocorr = librosa.core.autocorrelate(f0)
peaks = find_peaks(autocorr)
lag = peaks
pitch1 = sampleRate / lag
pitch.append(pitch1)
start, stop = stop, stop + 512
print(np.array(pitch))
print(len(pitch))
error output:
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-103-951880997936> in <module>
13 peaks = find_peaks(autocorr) # Find peaks of the autocorrelation
14 lag = peaks # Choose the first peak as our pitch component lag
---> 15 pitch1 = sampleRate / lag # Transform lag into frequency
16 pitch.append(pitch1)
17 start, stop = stop, stop + 512
TypeError: unsupported operand type(s) for /: 'int' and 'tuple'
I'm new to Python, is there any other way to get pitch per frame? Thank you.