As seen in the diagram, below I have a reference audio and a test audio. I want to find at what part of the test clip the reference audio be heard. Once, that is found I want to crop the test file from the point where the match begins and the point where the match ends. How can I do this matching and cropping of audio signals using Python? Some code will be of help.
The diagram below(from wiki) is for illustration purposes only
My audio clips: Reference audio: africaChirp Test audio: Africa
I want to find the time in seconds at which africaChirp appears in Africa. africaChirp was cropped from the source file, Africa, found in Dan Ellis: Music - Original and Synthetic.
I have also included my code to show my progress:
import numpy as np
import logging
from scipy.io import wavfile
rate2,test = wavfile.read('africa.wav')
#indices
testStart = 6000;
testEnd = 200000;
refStart = testStart + 11000;
refEnd = refStart + 2000 - 1;
testSig=test[testStart:testEnd]
refSig=test[refStart:refEnd]
refStartRel=refStart-testStart+1
refEndRel=refEnd-testStart+1
no_samples_test=testSig.shape[0]
no_samples_ref=refSig.shape[0]
xcorr=np.zeros((no_samples_test-no_samples_ref+1,1))
xcorr_norr=np.zeros((no_samples_test-no_samples_ref+1,1))
refSig_norm= np.linalg.norm(refSig)
for i in range(1,xcorr.shape[0]):
testSig_samples=testSig[i:(i+no_samples_ref)]
xcorr[i]=np.sum(np.multiply(testSig_samples,refSig))
linalgnorm=np.linalg.norm(testSig_samples)
xcorr_norr[i]=xcorr[i]/np.multiply(refSig_norm,linalgnorm)
xcorr_max_id=np.max(np.abs(xcorr_norr))
print(xcorr_max_id)