MATLAB stop Recording audio halfway through

1 次查看(过去 30 天)
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

回答(1 个)

Dhruv
Dhruv 2023-4-21
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.

类别

Help CenterFile Exchange 中查找有关 Audio Processing Algorithm Design 的更多信息

产品


版本

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by