Reputation: 3
i want to record voice from mic in MATLAB. but i don't want to decide when to stop the recording upfront, so i look for a way to stop while recording.
i've tried the follow code:
clc
clear
close all
r = audiorecorder(44100, 16, 1);
record(r); % speak into microphone...
pause(r);
p = play(r); % listen
resume(r); % speak again
stop(r);
p = play(r); % listen to complete recording
mySpeech = getaudiodata(r, 'int16'); % get data as int16 array
but i got some errors:
??? Error using ==> audioplayer.audioplayer at 68
Recorder is empty.
Error in ==> audiorecorder.play at 28
player = audioplayer(obj);
Error in ==> record2 at 10
p = play(r); % listen
if anyone can help me and explain to me why it dosen't work, i'll be very thankful :)
Upvotes: 0
Views: 2104
Reputation: 539
If you don't want to have constant time of recording consider calling these functions manually (I assume that you have audiorecorder object 'r'):
record(r);
to start recording
stop(r);
to stop recording (whenever you want)
play(r);
to play recorded sound
All comands have to be called manually (from Matlab Command Window) because in one script there is very short time between start and pause recording and nothing is recorded.
and one more thing - your code works fine in my environment - no errors at all
Upvotes: 0
Reputation: 36710
You can assume that no time passes between record
and pause
, nothing is recorded. Use record
or recordblocking
with a duration parameter set.
Upvotes: 1