MATLAB Answers

How to save wave file with arbitrary name right after recording is finished.

2 views (last 30 days)
DAO HONG SON
DAO HONG SON on 12 Nov 2020
Commented: DAO HONG SON on 13 Nov 2020
Someone please help me? I really had a lot of trouble.
I want as soon as the recording is finished the son01.wav file will not automatically save, but rather it will be asked to save by a different name option with each recording for different people. And I want this to be repeated for all of those after that.
Fs=44100;
N=16;
channel=2;
duration=3;
recObj = audiorecorder(Fs, N, channel);
disp('Start speaking.')
% Record in 3 seconds
recordblocking(recObj, duration);
disp('End of Recording.');
% Listen again
play(recObj);
% save sound to array
y = getaudiodata(recObj);
% Ve dang am theo thoi gian
% plot(y);
%save wave file with a new name
[newfile,newpath] = uiputfile('my_new_name.wav','save file name');
% save file wave
audiowrite('son01.wav',y,Fs)
I added this code "[newfile, newpath] = uiputfile ('my_new_name.wav', 'save file name');" and it works separately, son.01wav is automatically saved by "audiowrite ('son01.wav', y, Fs)" command.
I don't want this to happen. Someone please help me. thank you.

  4 Comments

Show 1 older comment
DAO HONG SON
DAO HONG SON on 13 Nov 2020
I want, after recording, this recording file will be saved with a new any new name. And this .wav file will be saved at the address 'C: \ Users \ 6 \ Desktop \ 1_Speech-Recognition \ data'. And I want this to be repeated any time I want to record. Can you please help me with the complete code from recording to save the file? thank you very much.

Sign in to comment.

Accepted Answer

Geoff Hayes
Geoff Hayes on 13 Nov 2020
Dao - perhaps you want to try something like
[newfile,newpath] = uiputfile('my_new_name.wav','save file name');
if isstring(newfile)
audiowrite(fullfile(newpath,newfile), y, Fs);
else
fprintf('Invalid file name.\n');
end
where we use the output from the uiputfile to write the audio data to that file.

  3 Comments

DAO HONG SON
DAO HONG SON on 13 Nov 2020
It still can't save the wav file I just finished recording. it shows the message 'Invalid filename'. I want, after recording, this recording file will be saved with a new any new name. And this .wav file will be saved at the address 'C: \ Users \ 6 \ Desktop \ 1_Speech-Recognition \ data'. And I want this to be repeated any time I want to record. Can you please help me with the complete code from recording to save the file? thank you very much.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!