read all audio files in one directory
27 次查看(过去 30 天)
显示 更早的评论
Hi, I want to remove a frequency from all my mp3 songs, my idea is to use the audioread and audioinfo functions to copy a song in my workspace, see if i can use the filter I created, with a sample rate of 44.1kHz and cut out the frequency (1kHz +/- 300Hz). With audiowrite I can create a .wav file without that frequency. But its a lot of work to do that for every song, is it possible to read the first song in one directory, filter it and generate a wav file in another directory and continue with the second song in the directory and so on? audioread expects the whole filename, I have no idea how to find out how many and which songs are in the directory, can anyone help me?
0 个评论
采纳的回答
Azzi Abdelmalek
2016-7-17
folder='C:\Users\malek\Documents\MATLAB'
audio_files=dir(fullfile(folder,'*.m'))
for k=1:numel(audio_files)
filename=audio_files(k).name
%Do what you want with filename
% create a new file name 'new_file' for example
folder_destination='C:\Users\malek\Documents' % for example
file_dest=fullfile(folder_destination,'new_file'
% .....
end
12 个评论
Walter Roberson
2020-11-30
see the first example in the fft documentation for information on plotting
更多回答(1 个)
Image Analyst
2016-7-17
See the second code sample in the FAQ; http://matlab.wikia.com/wiki/FAQ#How_can_I_process_a_sequence_of_files.3F
2 个评论
Josh Burt
2021-2-18
Hola image Analyst
I have attempted to use your code in the link on MatlabFandom - I am struggling to actually save the .wav files I need.
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
Image Analyst
2021-2-18
AudioArray{k} = audioread(fullFileName);
maxaudio(k) = max(AudioArray{k});
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Signal Processing Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!