How can I save a file .wav with any name in any folder?

2 ビュー (過去 30 日間)
David
David 2013 年 12 月 15 日
回答済み: Kirthi Kirthi 2018 年 4 月 12 日
Hello everyone,
I'm doing an audio processing program.
  1. The user records a sound
  2. He does the proper processing
  3. He saves the new sound in the folder he wants with the name he wants.
So, what I've done is:
>> [signal,FS,NBITS]=wavread('clar.wav');
>> wavwrite(signal, FS, NBITS, 'new_sound'); % saves a file with the name new_sound.wav in the current folder
>> uiputfile('.wav','Save sound','new_sound.wav');
However,
  1. uiputfile doesn't save the file in another folder.
  2. In the current folder, uiputfile doesn't save the file with another name.
This is the window it appears when I execute uiputfile. Of course it contains a new_sound.wav file because the wavwrite.
And then, I try to save it in this other folder.
I've repeated the same operation and as you can see, in the MATLAB folder it doesn't exist any new_sound.wav file.
Could you suggest me something?
------------------------------------------------------------------------------------------------------------------------------------------
SOLUTION FROM dbp:
[i,fs,nbits]=wavread('sound.wav');
[nfname,npath]=uiputfile('.wav','Save sound','new_sound.wav');
if isequal(nfname,0) || isequal(npath,0)
return % or whatever other action if 'CANCEL'
else
nwavfile=fullfile(npath, nfname);
wavwrite(i,fs,nbits,nwavfile);
end
Thank you dbp!

採用された回答

dpb
dpb 2013 年 12 月 15 日
編集済み: dpb 2013 年 12 月 15 日
uiputfile doesn't do any saving at all--it simply returns the user-selected FILENAME, PATHNAME, and FILTERINDEX for the subsequent operation. How would it have any idea what it's actually to save or the necessary operations to do so without that information passed to it anywhere? All it knows is a starting location and suggested name for the user to accept/modify/abort.
You must then use those values in another operation to actually do the file operation itself.
Sotoo:
[nfname,npath]=uiputfile('.wav','Save sound','new_sound.wav');
if isequal(nfname,0) || isequal(npath,0)
return % or whatever other action if 'CANCEL'
else
nwavfile=fullfile(nfname,npath);
wavwrite(...,nwavfile); % fill in appropriate other arguments
end
  1 件のコメント
David
David 2013 年 12 月 17 日
Thank you very much! Now I understand how it works!
However there is a little mistake in your code (in function fullfile ). The correct code for everyone who has the same doubts than me is:
[i,fs,nbits]=wavread('sound.wav');
[nfname,npath]=uiputfile('.wav','Save sound','new_sound.wav');
if isequal(nfname,0) || isequal(npath,0)
return % or whatever other action if 'CANCEL'
else
nwavfile=fullfile(npath, nfname);
wavwrite(i,fs,nbits,nwavfile);
end
Thank you very much again!

サインインしてコメントする。

その他の回答 (1 件)

Kirthi Kirthi
Kirthi Kirthi 2018 年 4 月 12 日
how to save many wav files and call them in another different file .

カテゴリ

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