필터 지우기
필터 지우기

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

조회 수: 1 (최근 30일)
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.

채택된 답변

Paulo Silva
Paulo Silva 2011년 6월 25일
%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
Daniel Shub
Daniel Shub 2011년 6월 27일
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 2011년 6월 30일
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!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Introduction to Installation and Licensing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by