How to record audio continuously, and have access to last x seconds of data??
22 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
回答 (2 件)
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
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
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
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
参考
カテゴリ
Help Center および File Exchange で Audio I/O and Waveform Generation についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!