Matlab error in file path for a sound

832 views Asked by At

I'm using GUI matlab, I'm recording wav sound and save it in specific folder. When I press the play button an error occurs, the error is: The filename specified was not found in the MATLAB path. That's a small part of the recording button:

 name=strcat(year,'-',month,'-',day,'-',hour,'-',min,'-',sec);
             fullpath=fullfile('c:\monitoringsystem',name);
             wavwrite(y,44100,fullpath);
             y=[];

The play code:

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

How to solve this problem, with keeping to save the sound in a specific folder.

1

There are 1 answers

0
il_raffa On

To read an audio file which is not in the MatLab path with "audioread" you have to specify the full file path.

In the code you posted it is not clear how you build the sound list and how it is assigned to the listbox.

Nevrtheless, a possible solution could be the following: you might create a (N x 2) cellarray in whch you store, for each song, the filename and its path.

You can assign to the listbox only the filename, then you can use the index of the item selected in the list box to also access to the cell containing the path. Then, you have just to build the full file name (including the path) to be used in the call to audioread.

The imlementation of this solution depends on how you manages the list of sound.

To test this solution I've build a small GUI: I've manually created a list of song and their path in the "listbox1_CreateFcn" and build up the full file name in the pushbutton1_Callback as follows (I've used guidata to manage the soud list within the GUI):

function listbox1_CreateFcn(hObject, eventdata, handles)
% hObject    handle to listbox1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: listbox controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end

% Definition of the sound list
l_song{1,1}='song_1';
l_song{1,2}='c:\users\user_1\';
l_song{2,1}='song_2';
l_song{2,2}='c:\users\user_2\';
l_song{3,1}='song_3';
l_song{3,2}='c:\users\user_3\';

% Use guidata to manage the cellarray withn the GUI
my_guidata=guidata(gcf);
my_guidata.song_list=l_song;
guidata(gcf,my_guidata);
str=l_song(:,1)

set(hObject,'string',str)



function pushbutton1_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Get idx of the selected sound
v=get(handles.listbox1,'Value')
% Get the list of song and paths
my_guidata=guidata(gcf);
l_song=my_guidata.song_list;

disp(['Song path= ' l_song(v,2)])
disp(['Song namw= ' l_song(v,1)])

% Build the full file name to be used in audioread
f_name=strcat(fullfile(l_song(v,2),l_song(v,1)),'.wav')

Hope this helps.