Measuring time delay of audio signals Before anyone yells at me I fully realize that this question has been asked numerous times. I assure you that I've read through the existing questions and answers but I am still confused about part of the problem.

I have a sound source that plays music (A) in a closed environment. I have a mic  that I'm using to record  A. I am left with two wav files which share the same characteristics and length (number of samples).

My goal is calculate the time it took for A to reach the mic.

I am trying to perform the calculation using cross-correlation (numpy):

# Delay estimation
corr = numpy.convolve(original_audio, recorded_audio, 'full')
delay = int(len(corr)/2) - numpy.argmax(corr)
distance = delay / sample_rate * 343 # sample_rate == 22050, m/s = speed of sound
print("Distance full: %.2f cm" % (distance * 100))


I consistently obtain values in the 300,000 cm range. The distance between the speaker and mic is approximately 2 feet.

This is all pretty new to me so I'm sure I'm missing something obvious.

Thanks in advance.
Are you sure you shouldn't be using numpy.correlate instead of numpy.convolve?  To estimate delay, you want to cross-correlate your signals, not convolve them.  You'll possibly end up with a much larger delay by convolving.

Trying something simple:

x = [1, 0, 0, 0, 0 ];
y = [0, 0, 0, 0, 1 ];
conv = numpy.convolve(x,y); 
conv
array([0, 0, 0, 0, 1, 0, 0, 0, 0])
corr = numpy.correlate(x,y,"full");
corr
array([1, 0, 0, 0, 0, 0, 0, 0, 0])