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

21 vues (au cours des 30 derniers jours)
Jack Latham
Jack Latham le 4 Oct 2019
Commenté : Walter Roberson le 10 Oct 2019
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'

Réponses (2)

jibrahim
jibrahim le 9 Oct 2019
Modifié(e) : jibrahim le 9 Oct 2019
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 commentaires
jibrahim
jibrahim le 10 Oct 2019
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 le 10 Oct 2019
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.

Connectez-vous pour commenter.


Walter Roberson
Walter Roberson le 4 Oct 2019
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 commentaire
Jack Latham
Jack Latham le 4 Oct 2019
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.

Connectez-vous pour commenter.

Community Treasure Hunt

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

Start Hunting!

Translated by