Load and store several .wav files within multiple subfolders

조회 수: 3 (최근 30일)
Josh Burt
Josh Burt 2021년 2월 18일
댓글: Jan 2021년 3월 2일
Hola
I have attempted to use some code on MatlabFandom to load in a number of wav files from seperate subfolders- I am struggling to actually save the .wav files I need.
https://matlab.fandom.com/wiki/FAQ#How_can_I_process_a_sequence_of_files.3F
The files are hundreds of audiofiles relating to speach recognition, they all sit in different subfolders, each with its own date (there are 2 files per day). There are hundreds of subfolders with .wav files in them. I would like the .wav files to be read and saved in an array called 'AudioArray'. I run your code below, I receive an output listing all the file names. But there is no raw data available for me to analyse. I also want to do some processing once the file has been read - in this case I have just put max(audioArray) to show this. Gracias for all help!
% Specify the folder where the files live.
myFolder = 'C:\Users\myname\Documents\voicedata\Audio';
% Check to make sure that folder actually exists. Warn user if it doesn't.
if ~isfolder(myFolder)
errorMessage = sprintf('Error: The following folder does not exist:\n%s\nPlease specify a new folder.', myFolder);
uiwait(warndlg(errorMessage));
myFolder = uigetdir(); % Ask for a new one.
if myFolder == 0
% User clicked Cancel
return;
end
end
% Get a list of all files in the folder with the desired file name pattern.
filePattern = fullfile(myFolder, '**/*.wav'); % Change to whatever pattern you need.
theFiles = dir(filePattern);
for k = 1 : length(theFiles)
baseFileName = theFiles(k).name;
fullFileName = fullfile(theFiles(k).folder, baseFileName);
fprintf(1, 'Now reading %s\n', fullFileName);
% Now do whatever you want with this file name,
% such as reading it in as an image array with imread()
AudioArray = audioread(fullFileName);
maxaudio=max(AudioArray); %calculates the max value of each audiostored in audioArray
drawnow; % Force display to update immediately.
end
  댓글 수: 1
Rik
Rik 2021년 2월 18일
You are overwriting your audio data every iteration. The drawnow seems unnecessary, as you don't modify graphics objects.

댓글을 달려면 로그인하십시오.

답변 (1개)

Jan
Jan 2021년 2월 18일
AudioArray = cell(1, numel(theFiles));
for k = 1 : numel(theFiles) % NUMEL is more direct than LENGTH
baseFileName = theFiles(k).name;
fullFileName = fullfile(theFiles(k).folder, baseFileName);
AudioArray{k} = audioread(fullFileName);
end
  댓글 수: 2
Josh Burt
Josh Burt 2021년 3월 2일
Thankyou Jan. Please can you tell me where in my code I would position your code?
Jan
Jan 2021년 3월 2일
% [YOUR CODE]
% Get a list of all files in the folder with the desired file name pattern.
filePattern = fullfile(myFolder, '**/*.wav'); % Change to whatever pattern you need.
theFiles = dir(filePattern);
% [MY CODE]
AudioArray = cell(1, numel(theFiles));
for k = 1 : numel(theFiles) % NUMEL is more direct than LENGTH
baseFileName = theFiles(k).name;
fullFileName = fullfile(theFiles(k).folder, baseFileName);
AudioArray{k} = audioread(fullFileName);
end
Now all audio files imported to the cell array "AudioArray". You can access the values in a loop again.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Graphics Objects에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by