record and analyse real-time audio
조회 수: 3(최근 30일)
For a project im working on i need to record audiodata from a microphone and analyse it simultaneously. I found some threads on mathworks but yet couldnt figure out how to do it.
I startet very basic with this:
fs = 8000 %or whatever suits best
recorder = audiorecorder(fs,24,1); %setting up the recorder
recordblocking(recorder,2); %record 2 secs
data = getaudiodata(recorder); %extract the recorded 2 secs
This works fine for just 2 secs, but i cant find a way to do this with a 15 minute long recording, extracting every "new" 2 seconds...
i tried to obtain the function/timer combination but that didnt work.
I´d be glad to get some help,
thanks in advance!
jibrahim 2022년 6월 28일
When working with real-time audio, you should consider audioDeviceWriter, audioDeviceReader and audioPlayerRecorder.
Here is a possible pattern:
fs = 8000; % Sample rate
% Create microphone object
adr = audioDeviceReader(SampleRate=fs);
% Create a buffer to save microphone samples
buff = dsp.AsyncBuffer(Capacity = fs*2.5);
numIterations = floor(15*fs/adr.SamplesPerFrame);
for index=1:numIterations % run as long as you want
% Read from the microphone
frame = adr();
% Save data to buffer
% If you have enough data, do you analysis
if buff.NumUnreadSamples >= 2*fs
data = read(buff);
p = pitch(data,fs);