How can I record an audio from a tuggle button in the GUIDE ?

1 回表示 (過去 30 日間)
Samuel Vinocuna Carrion
Samuel Vinocuna Carrion 2020 年 7 月 31 日
回答済み: Geoff Hayes 2020 年 8 月 1 日
I have to make a voice recorder using GUIDE.
I don´t know if I can put the "audiorecorder object" in the handles, the code below is in the CallBack function of tuggle button , when I push the toggle button it gives me an error, it says "record is empty". I use "getaudiodata" because I also have to modify the voice. I need that record the voice, stop the record and save that in a vector.
handles.x = get(hObject,'Value')
handles.audio = audiorecorder(44100,16,1);
if handles.x == 1
record(handles.audio);
elseif handles.x == 0
stop(handles.audio);
y = getaudiodata(handles.audio);
audiowrite('Voz.wav',y,44100)
end
guidata(hObject, handles)
This is the error...
Error using audiorecorder/getaudiodata (line
765)
Recorder is empty.
Error in ProyectoS>togglebutton1_Callback
(line 136)
y = getaudiodata(handles.audio);

回答 (1 件)

Geoff Hayes
Geoff Hayes 2020 年 8 月 1 日
Samuel - I think that the problem is that you are creating a new audio player each time the callback is called:
handles.audio = audiorecorder(44100,16,1); % <--- creating this again
if handles.x == 1
record(handles.audio);
elseif handles.x == 0
Instead, try creating the recorder only if the button is toggled on:
if get(hObject,'Value') == 1
handles.audio = audiorecorder(44100,16,1);
record(handles.audio);
elseif get(hObject,'Value') == 0
stop(handles.audio);
y = getaudiodata(handles.audio);
audiowrite('Voz.wav',y,44100)
end
guidata(hObject, handles)
I removed the handles.x since that isn't strictly needed (unless some other callback is interested in this information).

カテゴリ

Help Center および File ExchangeAudio and Video Data についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by