To extract specific audio segments based on the timing information in your text file, you'll need to read the text file, parse the timing and name information, and then extract the corresponding segments from your audio file.The steps are implemented in the code below:
% Load the audio file
filename = 'your_audio_file.wav'; % Replace with your actual audio file
[y, Fs] = audioread(filename);
% Open and read the text file
fileID = fopen('test.txt', 'r');
data = textscan(fileID, '%f %f %s');
fclose(fileID);
% Extract columns from the text data
startTimes = data{1};
endTimes = data{2};
names = data{3};
% Specify the name to extract (e.g., 'john' or 'jim')
targetName = 'jim'; % Change to 'john' if needed
% Loop through each entry in the text file
for i = 1:length(names)
if strcmp(names{i}, targetName)
% Convert milliseconds to sample indices
startSample = round((startTimes(i) / 1000) * Fs) + 1;
endSample = round((endTimes(i) / 1000) * Fs);
% Extract the audio segment
cutData = y(startSample:endSample, :);
end
end
Hope this helps!