Having problem in placing a timer behind a togglebutton for audio recording!

2 Ansichten (letzte 30 Tage)
Dear All,
Actually I have a toggle button (togglebutton1). When I click on it first time, it starts recording. The next time I click it, it stops recording. This works fine with the following code:
function togglebutton1_Callback(hObject, eventdata, handles)
button_state = get(hObject,'Value');
if button_state == get(hObject,'Max')
recorder = audiorecorder(8000,8,1);
record(recorder);
set(handles.togglebutton1,'String','Stop Recording');
handles.recorder=recorder;
guidata(hObject,handles);
elseif button_state == get(hObject,'Min')
recorder=handles.recorder;
stop(recorder);
samples = getaudiodata(recorder,'uint8');
set(handles.togglebutton1,'String','Start Recording');
end
But what I want is that when you click on it for the first time, it starts recording. Then you can't press the button for 2 seconds. After 2 seconds, you can press the button to stop recording. This will make my recording duration of atleast 2 seconds. The recording could be greater than 2 seconds but the recording shouldn't be less than 2 seconds.
So, what I want is when you click on the togglebutton, it starts recording. Then the togglebutton gets disabled (enable=off) for 2 seconds. After atleast 2 seconds or more than 2 seconds recording, you can press the togglebutton again to stop recording.
What modifications would you suggest in the mentioned code?
Need it urgently.
Thank you.

Akzeptierte Antwort

Paulo Silva
Paulo Silva am 25 Jun. 2011
%code to start recording and start record
set(hObject,'enable','off')
pause(2)
set(hObject,'enable','on')
%now the user can click again on the button
  2 Kommentare
Daniel Shub
Daniel Shub am 27 Jun. 2011
You may also want to add something like this to the code to stop recording. If the user clicks to stop recording and then very quickly clicks to start recording again, the soundcard will likely crash. A pause of about 0.5 seconds should enough time to allow the hardware to reset.
Matlab Help Seeker
Matlab Help Seeker am 30 Jun. 2011
Hi Daniel,
I tried doing this but it works fine on my PC. But I could consider adding it keeping in mind that some PCs don't have much resources like mine :)
Thanks for the suggestion!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Audio I/O and Waveform Generation finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by