필터 지우기
필터 지우기

How to record audio continuously, and have access to last x seconds of data??

조회 수: 20 (최근 30일)
Jack Latham
Jack Latham 2019년 10월 4일
댓글: Walter Roberson 2019년 10월 10일
I would like to be able to record audio continuosly, and be able to process the last say 10 seconds of data. The recording may run for a while before I need to process the data, and so I need a solution which only saves the last 10 seconds, and doesn't save data from the whole period.
Can anyone suggest a way of implimenting this? I think this may be called a 'circular buffer'

답변 (2개)

jibrahim
jibrahim 2019년 10월 9일
편집: jibrahim 2019년 10월 9일
Jack,
you should get to what you want with audioDeviceReader and dsp.AsyncBuffer
% Create an audio device reader and set its properties based on your
% scenario
fs = 44100;
adw = audioDeviceReader('SampleRate',fs);
% Create a circular buffer.
% Set its capacity to 10 seconds
buff = dsp.AsyncBuffer('Capacity',10*fs);
while (1)
% Read from mic
frame = adw();
% Write the frame to the buffer
write(buff,frame);
end
% when you are ready, use read(buff,frameLength) to read from the buffer
  댓글 수: 4
jibrahim
jibrahim 2019년 10월 10일
Hi Jack,
This example might be helpful:
In particular, take a look at the last section:
Detect Commands Using Streaming Audio from Microphone
It shows how a trained network is used to classify commands in real time, as a singal is streaming in from a microphone. It uses audioDeviceReader and implements a cicular buffer using a variable waveBuffer (though you could use dsp.Asyncbuffer as well).
Walter Roberson
Walter Roberson 2019년 10월 10일
audiorecorder() is not the right tool for streaming audio, as it can only record for a pre-determined amount of time and accessing the data is while recording is running is a bit tricky sometimes.

댓글을 달려면 로그인하십시오.


Walter Roberson
Walter Roberson 2019년 10월 4일
Audio Systems Toolbox, use the device reader, and as you read the data, store it in a buffer large enough for the number of seconds you need plus the latency of responding to the user clicking to say "There! That data!"
Often the most efficient way to store data in such circumstances is with a "circular buffer" https://www.mathworks.com/matlabcentral/answers/65213-how-to-develop-a-fifo-circular-buffer-for-analyzing-real-time-data
  댓글 수: 1
Jack Latham
Jack Latham 2019년 10월 4일
Thanks, yeah that's exactly what I'm trying to do, it is implimenting a cicurcular buffer (for example with audioDeviceReader or audiorecorder) which I'm stuck with.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Audio and Video Data에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by