8

我正在做一个学校项目,我必须处理大型 wav 文件(> 250Mgb),我想知道,为什么当我将这样的文件读取到 audacity 软件时,读取和绘制大约需要 40 秒,但是当使用 script.io.wavfile.read 将其读取到 python,它永远存在。

所以我的问题是,Audacity 软件是如何让它这么快的,这是我可以在 python 中做的事情来让它这么快吗?

编辑:我在代码中添加了一个新部分,用于计算和绘制 wav 文件的包络,但问题是在尝试大型 wav 文件时,它只需要数年时间。

有什么方法可以更快地读取和处理大型 wav 文件?

这是我正在使用的代码:

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, chirp, resample
analytic_signal = hilbert(data)
amplitude_envelope = np.abs(analytic_signal)
instantaneous_phase = np.unwrap(np.angle(analytic_signal))
instantaneous_frequency = (np.diff(instantaneous_phase) /(2.0*np.pi) * fs)


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

0 回答 0