How to record audio continuously, and have access to last x seconds of data??
22 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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'
0 comentarios
Respuestas (2)
jibrahim
el 9 de Oct. de 2019
Editada: jibrahim
el 9 de Oct. de 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 comentarios
jibrahim
el 10 de Oct. de 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
el 10 de Oct. de 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.
Walter Roberson
el 4 de Oct. de 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
Ver también
Categorías
Más información sobre Audio I/O and Waveform Generation en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!