1

我需要通过修剪文件开头和结尾的“相对”静音来计算 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;

只需要有关如何通过采样窗口实际遍历矩阵的帮助。

4

1 回答 1

0

我不完全确定你想要实现什么,但我认为你可以使用你自己的建议(有点):

soundIdx                      = find(abs(w) > thold)
total_time_w_sound            = sum(abs(w) > thold)/fs;
time_from_first_sound_to_last = (soundIdx(end)-soundIdx(1))/fs;

它是您要寻找的其中之一吗?

于 2013-03-19T12:39:36.107 回答