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

4 Ansichten (letzte 30 Tage)
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

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 3 Mär. 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 Kommentare
Walter Roberson
Walter Roberson am 3 Mär. 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.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Produkte


Version

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by