Creating an array that contains recordblockings

2 次查看(过去 30 天)
Hello, first of all I'm new to matlab. What's the syntaxis to create an array that can store audio recordblockings and then create a file at each iteration with a different name. This is my code:
audios = ; % What do I put here so that it stores recordingblocks
Recording = audiorecorder;
for i = 1:3
disp('Recording ...')
recordblocking(Recording , 1);
disp('End of recording')
audio = getaudiodata(Recording );
sound(audio);
audios(i) = audio;
audiowrite('output0001.wav' , audios(i), 8000);
end
end

回答(1 个)

Geoff Hayes
Geoff Hayes 2015-2-22
Andrés - even though each iteration records only one second of audio data, it may be that each recording is of a different length (i.e. the audio array). In that case, your audios variable could be a cell array which will allow you to contain arrays of different lengths. Initialize it as
audios = cell(3,1);
and then initialize the kth element as
audios{k} = audio;
(I use k as the iterator since MATLAB treats i and j as representations for the imaginary number.)
To write each audio block to a different file, just do the following
filename = sprintf('output%04d.wav',k);
which will create file names such as
output0001.wav
output0002.wav
output0003.wav
etc.
Then write to file as
audiowrite(filename,audios{k},8000);
Try integrating the above into your code and see what happens.

Community Treasure Hunt

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

Start Hunting!

Translated by