-1

enter image description hereI'm trying to find which is the highest value of a wav file. First I read the wav and then I find the sample which the largest value, but now I need to know which is that value. I can't upload the wav file but you can try with anyone.

import matplotlib.pyplot as plt
import numpy as np
import wave
import sys


spf1 = wave.open('C:/Users/Martinez/Documents/Diego/Facultad/Proyecto Final/Mediciones Cubo/5 sentado/Lado 1_5 sentado.wav','r')

#Extract Raw Audio from Wav File
signal1 = spf1.readframes(-1)
signal1 = np.fromstring(signal1, 'Int16')

fs1 = spf1.getframerate()

#If Stereo
if spf1.getnchannels() == 2:
    print 'Just mono files'
    sys.exit(0)
#print np.arange(signal)
m_x = abs(signal1).argmax()
m_y = abs(signal1).max()

print m_x
print m_y

Time=np.linspace(0, len(signal1)/float(fs1), num=len(signal1))

fig = plt.figure()
ax1 = fig.add_subplot(111)
ax1.vlines(Time[m:], [0], abs(signal1)[m:] )
#ax1.plot(Time[m:], abs(signal1[m:]), 'r')
ax1.grid(True)
ax1.axhline(color='black', lw=2)

plt.show()
3
  • try print max(signal1) Oct 30, 2013 at 20:47
  • plots can be deceiving, print the 10 largest value like signal1.sort(); print signal1[-10:] Oct 30, 2013 at 21:08
  • Yes, I sort the array like you say and it seems that the largest value is 6025. Oct 30, 2013 at 21:37

1 Answer 1

1

If signal1 is an iterable of numbers (or anything sortable), then max(signal1) will give you maximum value. If you need to convert those items to numbers, then use the key argument: max(signal1, key=abs).

2
  • Yes, it is the largest considering + and - values, and in absolute value, it's 6929, doing: abs(signal1).max(), Am I right? Nov 1, 2013 at 20:16
  • @DiegoMartínezGiardini (a) No you're not right, the correct usage is as I have shown it (b) your python interpreter will tell you if that is right when you type it in.
    – Marcin
    Nov 2, 2013 at 14:21

Not the answer you're looking for? Browse other questions tagged or ask your own question.