首页 > 解决方案 > 在 python 中读取和处理大型 wav 文件的最佳方法是什么

问题描述

这是我用来读取.wav文件以计算信号包络的代码。它工作得很好,但是当我尝试读取一些大于 200MB 的文件时,它就不起作用了。

任何帮助真的很感激。

import matplotlib.pyplot as plt
import numpy as np
from scipy.io.wavfile import read
from tkinter import filedialog

# Browse, read the signal and extract signal informations (fs, duration)
filename = filedialog.askopenfilename(filetypes = (("""
            Template files""", "*.wav"), ("All files", "*")))

fs, data = read(filename, mmap=True)

T = len(data) / fs        #duration
nsamples = T * fs       #number of samples
time = np.linspace(0, T, nsamples)


# Compute the envelope of the signal
from scipy.signal import hilbert
analytic_signal = hilbert(data)

len_E = len(amplitude_envelope)
t2 = np.linspace(0,T,len_E)

# Plot the signal and its envelope
plt.figure()
plt.subplot(211)
plt.plot(time, data)

plt.subplot(212)
plt.plot(t2,amplitude_envelope)
plt.show()

标签: pythonwavlarge-files

解决方案


推荐阅读