问题
I wrote this code where I read a wav file and then It identifies where is the larger sample, but this only give me the possition of the max sample, but not the value of it, so what can I do to know which is its value? And when I plot it, why it doesn't fit on thw y-scale. For example, it says that the value is 6920, but when I plot, it only reaches 5535. Thank you!
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(signal1)
m = abs(signal1).max()
print m
Time=np.linspace(0, len(signal1)/float(fs), num=len(signal1))
fig = plt.figure()
ax1 = fig.add_subplot(111)
ax1.vlines(Time[m:], [0], abs(signal1)[m:] )
ax1.grid(True)
ax1.axhline(color='black', lw=2)
plt.show()
回答1:
won't abs(signal1).max()
do the trick?
来源:https://stackoverflow.com/questions/19686367/how-to-find-and-plot-the-largest-sample-in-a-wav-file