How to open a .wav file from matlab using a string name?

1 次查看(过去 30 天)
Hi,
... and thanks for helping.
I want to open a .wav file in matlab just from a string name. I don't know what the string name will be until I run the program. I do know that whatever the string name will be, it will exist in the current folder.I have tried multiple approaches unsuccessfully. below is the latest that I have produced
if true
list=get(handles.targetSelection_popupmenu,'String');
val=get(handles.targetSelection_popupmenu,'Value');
str=list{val};
filename=[sr,'.wav'];
[VoiceTrgt fsTrgt]=wavread(filename,'.wav');
end
It does not work. so, as you can guess, str can be, say, Symphony11 or Symphony12 or whatever... I want to read the Symphony.
Thanks.

回答(1 个)

Wayne King
Wayne King 2013-3-31
编辑:Wayne King 2013-3-31
Can you say what error you are getting? I'm not sure why you have the following
filename=[sr,'.wav'];
[VoiceTrgt fsTrgt]=wavread(filename,'.wav');
Why are you calling wavread with an '.wav' input argument? There is no such input argument. The above is probably giving you an "unrecognized data format" error because it expects a string like 'double' or 'native'
Just do the following
filename = [sr, '.wav'];
[VoiceTrgt fsTrgt]=wavread(filename);
Assuming that filename ends up as something like symphony11.wav.
By the way, the recommend functionality to use is audioread() assuming you have a version of MATLAB that contains that function.
  1 个评论
MatlabFan
MatlabFan 2013-3-31
First of all Wayne, Thank you for assisting me. I realized that I had two mistakes in my code: instead of sr it should have been str (see code above. Also, as you pointed out, I should not have called the wavread with a '.wav' input argument the way I did it in the code above. Thanks.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Data Type Conversion 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by