필터 지우기
필터 지우기

Process all files in folder using sprintf and audioread

조회 수: 2 (최근 30일)
Lasse Embøl
Lasse Embøl 2020년 5월 13일
답변: Lasse Embøl 2020년 5월 13일
I'm trying to process a sequence .mp3 files with different filenames, and get them to output in a subfolder with incrementing names.
However, the script can only find files with a certain filename structure. How can i use the script on all files in the folder, while using sprintf
to make an input, which is processed by audioread? Lastly, how can i reuse the input filename when adding a digit in the output part? (%d)
Ask if you need more info. I'm quite the beginner here.
numfiles = 600;
mydata = cell(1, numfiles);
FS = 16e3; % sampling rate
for loop = 1:numfiles
input = sprintf('sounds/sentence%d.mp3', loop); % this argument should take all mp3's in folder
[x,fs] = audioread(input);
x = resample(x, FS, fs);
y = vocoder(x, FS, 8, 160, 'NOISE', 1);
CISignal = y * (rms(x)/rms(y));
CISignal = CISignal/max(abs(CISignal(:)))
output = sprintf('sounds/output/sentence%d.wav', loop); %
fprintf('Saving %s\n', output);
audiowrite(output,CISignal,FS);
end
Thanks to everyone who can point in the right direction!
Sorry - but looking through dozens of Answers, none worked when using sprintf and audioread.
  댓글 수: 2
Stephen23
Stephen23 2020년 5월 13일
Do the filenames happen to use leading zeros in the numbers?
Lasse Embøl
Lasse Embøl 2020년 5월 13일
No, it's a string with some digits in the end, like seen in the code. With different combinations of letters, obviously
cheers

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

채택된 답변

Lasse Embøl
Lasse Embøl 2020년 5월 13일
I figured out the input using dir, and loading filenames from the resulting array:
path = 'pathtofiles';
a=dir(fullfile(path,'*.mp3'));
files = { a.name };
FS = 16e3; % sampling rate
for loop = 1:length(files)
input = files{loop};
[x,fs] = audioread(input);
% looping processing code here
end
Now I need to figure out how to export the files using the same name - but I guess that's for another question, if (when) I get stuck
cheers

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Environment and Settings에 대해 자세히 알아보기

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by