MATLAB stop Recording audio halfway through
4 views (last 30 days)
Show older comments
wrote this really simple script which should record arbitrarily long audio, split it into 10sec long blocks and create a .wav file for each one. Every single file has no audio after 5 sec. This reflects even if i change preferred block duration, ex: if i want file to be 20 sec long I only get 10 sec of audio followed by 10 sec silence, etc... tried plotting the signal, shows same result.
example of plot:
my script:
function record
Fs = 16000;
nBits = 16;
nChannels = 1;
recobj1 = audiorecorder(Fs, nBits, nChannels);
BlockSize = 10;
record(recobj1, BlockSize);
countBlocks = 0;
T1 = cputime;
while (1)
T2 = cputime;
if T2 - T1 > BlockSize
time = (countBlocks - 1) * BlockSize+1/Fs: 1/Fs :countBlocks*BlockSize;
stop(recobj1);
x = getaudiodata(recobj1);
T1 = cputime;
record(recobj1, BlockSize);
x(length(time)) = 0;
countBlocks = countBlocks + 1;
name = sprintf('output%d.wav', countBlocks);
audiowrite(name, x, Fs)
end
end
Answers (1)
Dhruv
on 21 Apr 2023
There could be a few potential issues causing the recording to stop halfway through.
- One possibility is that the buffer size used for the recording is not large enough to store the entire block of audio, so it cuts off prematurely.
- Another possibility is that the processing power of the computer running the script is not sufficient to handle the continuous recording and processing of the audio data.
To work around these issues, try adjusting the buffer size used for the recording to ensure that it can store the entire block of audio. Also try reducing the processing load on the computer by closing other applications or processes that may be consuming resources.
Additionally, consider using a pre-built toolbox or function specifically designed for continuous audio recording such as Audio Toolbox which may be more optimized for this task and provide better performance.
0 Comments
See Also
Categories
Find more on Audio Processing Algorithm Design in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!