Microphone recording starts with delay
4 views (last 30 days)
Show older comments
Hello community,
I´m recording the microphone and later I want to find the major frequency by using filters.
Actually I have the problem, that the record is starting with a delay of 0.5 seconds. Do you have any ideas how to solve the problem? Or how can I get the data only from second 1 to second 4 from the plot for example?
Thanks a lot!

%Definitionen
Abtastfrequenz = 44100;
BitSample = 16;
%Grafiken schließen
close all;
%Mikro-Aufnahme
recorder = audiorecorder(Abtastfrequenz,BitSample,1,-1);
pause(4)
disp('Aufnahme gestartet');
recorder.record(Aufnahmelaenge)
while recorder.isrecording()
pause(0.1);
plot(recorder.getaudiodata());
drawnow();
end
disp('Aufnahme beendet');
figure(1)
xlabel('Samples');
ylabel('Amplitude');
title('Mikrofon - Amplitude / Samples')
%axis([0.5 2 -0.015 0.015]);
%Amplitude
h = findobj(gca,'Type','line');
s=get(h,'Xdata');
y=get(h,'Ydata');
y_spalte = transpose(y);
t = s/Abtastfrequenz;
t_spalte = transpose(t);
%details(y);
xTable = timetable(seconds(t_spalte),y_spalte);
figure(2)
plot(t,y);
xlabel('Zeit in Sekunden');
ylabel('Amplitude');
title('Mikrofon - Amplitude / Zeit')
0 Comments
Answers (1)
Geoff Hayes
on 29 Apr 2020
Steffen - are you sure that there is something to record for the first half-second? Does this "delay" always occur?
As for extracting the data from the plot, if you store the handle to the plot object, then you can get the data. Or you could just use the data from the audio recorder object.
hPlot = [];
while recorder.isrecording()
pause(0.1);
hPlot = plot(recorder.getaudiodata());
drawnow();
end
% get the audio data from the plot
audioData = get(hPlot, 'XData');
audioDataSubset = audioData(Abtastfrequenz+1:4*Abtastfrequenz);
% get the audio data from the recorder
audioDataRecorder = recorder.getaudiodata();
audioDataRecorderSubset = audioDataRecorder(Abtastfrequenz+1:4*Abtastfrequenz);
I've assumed that you would want to do this outside of the loop but....how do you expect to exit the loop? Where do you pause or stop the recording? Or is that the purpose of Aufnahmelaenge?
2 Comments
Selene Petit
on 25 May 2021
Good morning! I have the exact same problem, of there being a constant 400ms delay before any sound is recorded (at least it seems to be constant across recordings and users, as Steffen seems to have the same problem. Do you know what may be happening? I'm using the following parameters for my audiorecorder:
recObj = audiorecorder(44100, 16, 1);

Many thanks,
Selene
Geoff Hayes
on 26 May 2021
Hi Selene - I see the same with my version of MATLAB. It could be that it takes a half-second (or less) for the software to request the necessary resources (microphone). Knowing that there is this delay, can your compensate for it?
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!