Problem with StopRecording button
I’m using this code to record my voice, but when the recording is less than 5 seconds, the file played by the function sound is the file recorded before the last one.
This function records the voice when i push the ‘StartRecording’ button:
function StartRecording_Callback(hObject, eventdata, handles)
RecordStatus = get(hObject,’Value’);
runstr=get(hObject,’string’);
if RecordStatus == 1
% start recording
fs = 44100;
obj = audiorecorder(fs, 16, 1);
recordblocking(obj, 5);
y = getaudiodata(obj);
clear obj
save recording.mat y
else
% stop recording
StopRecording(handles);
end
This function is the callback for the function StopRecording:
function StopButton_Callback(hObject, eventdata, handles)
StopRecording(guidata(hObject));
This function saves, plays and plots the audio file:
function StopRecording(handles)
fs = 44100;
load recording y;
[filename, pathname] = uiputfile(‘*.wav’, ‘Save file name’);
cd (pathname);
audiowrite(filename, y, fs);
sound(y,fs);
handles.x = y;
handles.fs = fs;
axes(handles.axes1);
time = 0:1/fs:(length(handles.x)-1)/fs;
plot(time,handles.x);
title(‘Original Signal’);
axes(handles.axes2);
specgram(handles.x, 1024, handles.fs);
title(‘Encrypted Signal’);
I want to record, play and plot the file just created.I’m using this code to record my voice, but when the recording is less than 5 seconds, the file played by the function sound is the file recorded before the last one.
This function records the voice when i push the ‘StartRecording’ button:
function StartRecording_Callback(hObject, eventdata, handles)
RecordStatus = get(hObject,’Value’);
runstr=get(hObject,’string’);
if RecordStatus == 1
% start recording
fs = 44100;
obj = audiorecorder(fs, 16, 1);
recordblocking(obj, 5);
y = getaudiodata(obj);
clear obj
save recording.mat y
else
% stop recording
StopRecording(handles);
end
This function is the callback for the function StopRecording:
function StopButton_Callback(hObject, eventdata, handles)
StopRecording(guidata(hObject));
This function saves, plays and plots the audio file:
function StopRecording(handles)
fs = 44100;
load recording y;
[filename, pathname] = uiputfile(‘*.wav’, ‘Save file name’);
cd (pathname);
audiowrite(filename, y, fs);
sound(y,fs);
handles.x = y;
handles.fs = fs;
axes(handles.axes1);
time = 0:1/fs:(length(handles.x)-1)/fs;
plot(time,handles.x);
title(‘Original Signal’);
axes(handles.axes2);
specgram(handles.x, 1024, handles.fs);
title(‘Encrypted Signal’);
I want to record, play and plot the file just created. I’m using this code to record my voice, but when the recording is less than 5 seconds, the file played by the function sound is the file recorded before the last one.
This function records the voice when i push the ‘StartRecording’ button:
function StartRecording_Callback(hObject, eventdata, handles)
RecordStatus = get(hObject,’Value’);
runstr=get(hObject,’string’);
if RecordStatus == 1
% start recording
fs = 44100;
obj = audiorecorder(fs, 16, 1);
recordblocking(obj, 5);
y = getaudiodata(obj);
clear obj
save recording.mat y
else
% stop recording
StopRecording(handles);
end
This function is the callback for the function StopRecording:
function StopButton_Callback(hObject, eventdata, handles)
StopRecording(guidata(hObject));
This function saves, plays and plots the audio file:
function StopRecording(handles)
fs = 44100;
load recording y;
[filename, pathname] = uiputfile(‘*.wav’, ‘Save file name’);
cd (pathname);
audiowrite(filename, y, fs);
sound(y,fs);
handles.x = y;
handles.fs = fs;
axes(handles.axes1);
time = 0:1/fs:(length(handles.x)-1)/fs;
plot(time,handles.x);
title(‘Original Signal’);
axes(handles.axes2);
specgram(handles.x, 1024, handles.fs);
title(‘Encrypted Signal’);
I want to record, play and plot the file just created. sound, audiowrite, audiorecorder MATLAB Answers — New Questions