how can extract data from txt file?
10 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
I am trying to read a specific name from the text file which correspond to mseconds( for example Jim and John occurances) and depends of the timing correspond to the name I would like to extract an audio signal but only the specified mseconds which are read from the txt file.
my current code:
filename= 'test.txt';
[y, Fs]= audioread(filename);
cutData= y(((Fs*(652-1))+1:Fs*(767-1)/2-10,:);
plot(linspace(0.652,0.767,length(cutData)),cutData);
0 comentarios
Respuestas (1)
TED MOSBY
el 13 de Nov. de 2024 a las 4:37
Editada: TED MOSBY
el 18 de Nov. de 2024 a las 19:55
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!
0 comentarios
Ver también
Categorías
Más información sobre Audio and Video Data en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!