How to find and plot the largest sample in a wav f

2019-09-19 08:42发布

enter image description hereI 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()

标签: python wav
1条回答
混吃等死
2楼-- · 2019-09-19 09:04

won't abs(signal1).max() do the trick?

查看更多
登录 后发表回答