【问题标题】:Matlab error when playing a sound播放声音时的Matlab错误
【发布时间】:2015-06-14 08:28:28
【问题描述】:

我正在使用 matlab gui,我正在录制声音,然后将其保存在 c 中的文件夹中,然后当我按下声音 wav 上的播放时,将录制的声音显示在列表框中的文件夹中。 matlab报错错误是:

************Error using audioread (line 74)**
***The filename specified was not found in the MATLAB path.
Error in Monitoring_System>play_Callback (line 178)
[q, Fs] = audioread(thisstring);
Error in gui_mainfcn (line 95)
        feval(varargin{:});
Error in Monitoring_System (line 42)
    gui_mainfcn(gui_State, varargin{:});
Error in @(hObject,eventdata)Monitoring_System('play_Callback',hObject,eventdata,guidata(hObject))

Error while evaluating uicontrol Callback*************

-记录代码:

format shortg
             c = clock;
             fix(c);
             a=num2str(c);
             year=strcat(a(1),a(2),a(3),a(4),a(5));
             month=strcat(a(19),a(20));
             day=strcat(a(33),a(34));
             hour=strcat(a(48),a(49));
             min=strcat(a(63),a(64));
             sec=strcat(a(74),a(75));
             name=strcat(year,'-',month,'-',day,'-',hour,'-',min,'-',sec);
             fullpath=fullfile('c:\monitoringsystem',name);
             wavwrite(y,44100,fullpath);
             y=[];

在列表框中显示它们的代码:

d = dir('C:\monitoringsystem\*.wav'); %get files


set(handles.listbox1,'String',{d.name}) 

播放从列表框中选择的声音的代码:

allstrings = cellstr( get(handles.listbox1, 'String') );
curvalue = get(handles.listbox1, 'Value');
thisstring = allstrings{curvalue};
[q, Fs] = audioread(thisstring);
 soundsc(q,44100);

任何帮助如何解决此问题,并保留保存在特定文件夹中。我将录制的声音复制到 matlab 文件夹中,然后在 gui 中按下 play 来播放 wav 声音,它没有给出任何错误。

【问题讨论】:

    标签: matlab user-interface audio error-handling


    【解决方案1】:

    您是否尝试过调试它并在选择文件后查看d 包含的内容?

    As per the documentation, d = dir('C:\monitoringsystem\*.wav'); 返回带有以下字段的structname,date,bytes,isdir,datenum(至少在 MATLAB 2015a 上)。尽管{d.name} 为您提供了正确的文件名,但您应该注意这只是一个相对路径,因此除非文件位于活动目录中,否则 MATLAB 不会在哪里查找文件。

    我不完全确定您为什么在使用 allstringscurvaluethisstring 时遇到了所有麻烦,但如果我正确理解您想要做什么,我会建议两种方法中的一种:

    1. 在常量中定义默认路径(即C:\monitoringsystem),然后在保存\加载时使用:

      DEFAULT_PATH = `C:\monitoringsystem`; %// Definition
      ...
      fullpath = fullfile(DEFAULT_PATH,name); %// When saving
      ...
      d = dir(fullfile(DEFAULT_PATH,'*.wav')); %// When listing files
      ...
      [q, Fs] = audioread(fullfile(DEFAULT_PATH,{d.name})); %// When reading a file
      
    2. 使用uigetfile

      [FileName,PathName] = uigetfile('*.wav','Select the WAV file');
      FullPath = fullfile(PathName,FileName);
      

      (然后其余的与第一种情况非常相似)

    【讨论】:

      猜你喜欢
      • 2013-08-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多