As per the code shared, in order to apprpriately cut the audio signal into segments as per the specified list of intervals, consider indexing the data in the following way:
[data, Fs] = audioread('sound.wav');
list = {'0.300000 0.410000', '0.41000 0.430000' , ...}
for k = 1:length(list)
interval = list{k};
x = str2num(interval);
if length(x) == 2
start = x(1);
stop = x(2);
startIdx = max(1, floor(start * Fs));
stopIdx = min(length(data), ceil(stop * Fs));
segment = data(startIdx:stopIdx); % Indexing appropriately taking Fs(Sampling frequency) into account
sound(segment, Fs); % Fs(Sampling frequency) helps in obtaining the correct aound output.
end
end
The following MATLAB Answer and Mathworks documentations can be referred to know more:
'Signal Labeller': https://www.mathworks.com/help/signal/ref/signallabeler-app.html
Hope this helps! Thanks.
