How to make real time audio recording of 1 sec in matlab?
4 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Saurabh Deshmukh
am 3 Mär. 2023
Bearbeitet: Saurabh Deshmukh
am 6 Mär. 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 Kommentare
Akzeptierte Antwort
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
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.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Audio and Video Data finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!