简体   繁体   English

如何在WAV文件中查找和绘制最大样本

[英]How to find and plot the largest sample in a wav file

在此处输入图片说明 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? 我在读取wav文件的地方编写了这段代码,然后它标识了较大的样本在哪里,但这仅使我拥有最大样本的位置,但没有给出它的值,因此我该怎么办才能知道哪个是它的值? And when I plot it, why it doesn't fit on thw y-scale. 当我绘制它时,为什么它不适合y尺度。 For example, it says that the value is 6920, but when I plot, it only reaches 5535. Thank you! 例如,它说值是6920,但是当我绘制时,它只达到5535。谢谢!

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()

abs(signal1).max()不会成功吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM