0

我试图使用下面的代码为wav 文件的所有通道绘制时间与幅度的关系。但是我看到 matplotlib在我的一个频道上绘制了一个不存在的正弦波。大胆似乎正在策划正确的事情,我错过了什么?

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

f = wave.open('captured_Mic1_22_09_20_1738.wav')
sampleRate = f.getframerate()
totalFrames = f.getnframes()

print(f.getnchannels())

data = f.readframes(-1) # -1 is read all frames, can also use totalFrames
# print(data)  # Data in Hex

dataInt = np.frombuffer(data, np.int16)
print("All Samples -> {}".format(dataInt))

dataInt.shape = -1,2
print("L and R in 2 columns \n {}" .format(dataInt))

dataInt = dataInt.T
print("L and R in two separate rows \n {}" .format(dataInt))

print("total duration of file -> {}" .format(totalFrames/float(sampleRate)))
duration = 1/float(sampleRate)
print(duration)

timeSeq = np.arange(0, totalFrames/float(sampleRate), duration)

# plt.plot(timeSeq, dataInt[0])
# plt.show()

plt.plot(timeSeq, dataInt[1])
plt.show()

matplotlib vs audacity 图 代码学分

4

1 回答 1

0

我使用下面的 2 行打印了dataInt缓冲区的全部内容以查看是否有任何数据。

np.set_printoptions(threshold=np.inf)
print(dataInt[1])

幅度非常小,因此看起来没有关于大胆的数据。这是一张放大了很多大胆的屏幕截图。

在此处输入图像描述

于 2021-08-09T14:29:09.723 回答