Problem with StopRecording button
Afficher commentaires plus anciens
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.
Réponses (1)
Jengiz Basatov
le 16 Jan 2021
Déplacé(e) : Christopher Stapels
le 16 Mai 2024
U can use this code :
val= get(hObject,'Value');
runstr=get(hObject,'string');
fs=44100;
record=audiorecorder(fs,16,1);
recordblocking(record,10);
y=getaudiodata(record);
[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('Orijinal sinyal');
axes(handles.axes2);
windows_length=ceil(20*fs/1000);
specgram(handles.x,windows_length,windows_length/2);
title('Orjinal sinyalin spektogrami');
xlims=num2str(get(handles.axes1,'Xlim'));
ylims=num2str(get(handles.axes1,'Ylim'));
handles.zoom_history=[];
end
guidata(hObject,handles);
Catégories
En savoir plus sur Audio and Video Data dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!