如何找到并绘制 wav 文件中的最大样本 [英] How to find and plot the largest sample in a wav file

查看:19
本文介绍了如何找到并绘制 wav 文件中的最大样本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了这段代码,我读了一个 wav 文件,然后它标识了更大的样本,但这只能给我最大样本的位置,而不是它的值,所以我该怎么做才能知道它的值是多少?当我绘制它时,为什么它不适合 y 尺度.例如,它说值是 6920,但是当我绘图时,它只达到了 5535.谢谢!

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

推荐答案

不会 abs(signal1).max() 解决问题吗?

这篇关于如何找到并绘制 wav 文件中的最大样本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆