Having problem in placing a timer behind a togglebutton for audio recording!
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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.
0 comentarios
Respuesta aceptada
Paulo Silva
el 25 de Jun. de 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 comentarios
Daniel Shub
el 27 de Jun. de 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.
Más respuestas (0)
Ver también
Categorías
Más información sobre Audio I/O and Waveform Generation en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!