我需要通过修剪文件开头和结尾的“相对”静音来计算 wav 文件的长度,然后以毫秒为单位返回持续时间。我知道您可以这样找到 wav 文件的持续时间:
[w,fs] = wavread('file.wav');
length = length(w)/fs;
我的逻辑是使用波形矩阵的第一列(左通道),得到一个任意阈值,然后通过采样窗口遍历矩阵。如果这些窗口的最大值大于阈值,那么我开始计算时间。当这个窗口的最大值小于我停在那里的值时。这是我到目前为止所拥有的:
%Just use the first column in the waveform matrix, 2 gives strange results
w = w(:,1);
%Get threshold value by multiplying max amplitude of waveform and
%predetermined percentage (this varies with testing)
thold = max(w) * .04;
只需要有关如何通过采样窗口实际遍历矩阵的帮助。