MATLAB stop Recording audio halfway through

3 ビュー (過去 30 日間)
Aleksandr Marcovich
Aleksandr Marcovich 2023 年 4 月 6 日
回答済み: Dhruv 2023 年 4 月 21 日
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 件のコメント
Aleksandr Marcovich
Aleksandr Marcovich 2023 年 4 月 6 日
just noticed a little delay at the beginning of the recording as well...

サインインしてコメントする。

回答 (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 Center および File ExchangeAudio 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