How to make real time audio recording of 1 sec in matlab?
4 views (last 30 days)
Show older comments
Saurabh Deshmukh
on 3 Mar 2023
Edited: Saurabh Deshmukh
on 6 Mar 2023
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
0 Comments
Accepted Answer
Walter Roberson
on 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 Comments
Walter Roberson
on 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.
More Answers (0)
See Also
Categories
Find more on Audio and Video Data in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!