How to make real time audio recording of 1 sec in matlab?

4 visualizzazioni (ultimi 30 giorni)
I am trying to record 1 sec audio from microphone and save it into a .wav file along with time stamps. However, when output is verified , the code is not recording per sec instead there is a delay of 2 to 4 sec between two sucessive recordings. Here is the code. I dont know what is going wrong and why there is time delay between two recording audio files
for i=1:25
Fs=44100;
disp('Recording Thread')
DataBaseDir='C:\Path';
recorder = audiorecorder(44100,16,1,1);
recordblocking(recorder,1);
y=getaudiodata(recorder);
file = sprintf('%s.wav', datetime(("now"),Format="HH mm ss"));
filename=[DataBaseDir '\' file];
audiowrite(filename,y,Fs);
end

Risposta accettata

Walter Roberson
Walter Roberson il 3 Mar 2023
It takes time to construct the recording object. It takes time to retrieve the recorded samples. It takes time to write the samples to file.
You should switch to using Audio System Toolbox and using the audio device recorder system object, which can run continuously.
  3 Commenti
Walter Roberson
Walter Roberson il 3 Mar 2023
%tested
DataBaseDir = '.'; %or as appropriate
Fs = 44100;
recorder = audioDeviceReader('SampleRate', Fs, ...
'BitDepth', '16-bit integer', ...
'NumChannels', 1, ...
'SamplesPerFrame', Fs);
writer = dsp.AudioFileWriter('SampleRate',Fs);
for i=1:25
filename = fullfile(DataBaseDir, sprintf('%s.wav', datetime("now",Format="HH mm ss")));
release(writer);
writer.Filename = filename;
y = recorder();
writer(y);
end
release(reader)
release(writer) %necessary to flush last frame to file
This takes a while to get going.

Accedi per commentare.

Più risposte (0)

Prodotti


Release

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by