필터 지우기
필터 지우기

Unable to play .wav file

조회 수: 1 (최근 30일)
Jan Donyada
Jan Donyada 2011년 8월 31일
댓글: Irene Lia Arabes 2015년 2월 12일
Hi guys, for some reason, some odd errors occur when i try to run my text to speech program. i created it using GUIDE. i get 5 errors:
#1. wavread fails to open file
#2. the line [y, Fs] = wavread(wordsarray{1}{m}); returns an error, perhaps the syntax i have used is wrong or inadequate. basically im trying to reference the element of the cell array created by the textscan of the user string input. #3, #4 , #5. Errors #3-#5 appear in the GUI default m file that's created when using GUIDE:
#3. Error in ==> gui_mainfcn at 96 feval(varargin{:});
the above line appears in:
varargin{1} = gui_State.gui_Callback;
if nargout
[varargout{1:nargout}] = feval(varargin{:});
else feval(varargin{:});
#4. gui_mainfcn(gui_State, varargin{:});
the above line once again appears in the gui_mainfcn which is created upon creation of the gui using GUIDE.
#5. Error in ==> @(hObject,eventdata)tts2('pushbutton1_Callback',hObject,eventdata,guidata(hObject))
??? Error while evaluating uicontrol Callback
unfortunately i have no idea what the last error means.. the following is the code i've written for the pushbutton callback. basically its supposed to match the string with the corresponding wav file, load it with wavread(), and then play it with sound() (basically the 'hello' appends to 'hello.wav').
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)
words = get(handles.editbox, 'string'); %scans user input string from editbox
wordsarray = textscan (words, '%s'); %puts words into cell array
n = length(wordsarray{1}); %stores number of words in user input string
for m = 1:n
[y, Fs] = wavread(wordsarray{1}{m}); %this is supposed to load the corresponding wav file. the wav files are named after the words, eg. the wav file for the word "hello" is "hello.wav"
sound(y, Fs); %plays the loaded wav file
end

채택된 답변

Walter Roberson
Walter Roberson 2011년 8월 31일
I do not see anything wrong on first reading, but I would suggest that your code would be clearer if you were to use
wavedirectory = './'; %if current directory, adjust if in different directory
wordsarray = textscan(words, '%s');
wavnames = wordsarray{1};
for m = 1:length(wavnames)
thisfid = [wavedirectory wavenames{m} '.wav'];
try
[y, Fs] = wavread(thisfid);
sound(y, Fs);
catch
fprintf(1,'Failed to process file wave "%s" because: ', thisfid);
lasterror
end
end
  댓글 수: 5
Walter Roberson
Walter Roberson 2011년 9월 1일
Before the textscan:
words = lower(words);
words(~ismember(words, ['a':'z' ' '])) = ' ';
then go ahead with the textscan
Irene Lia Arabes
Irene Lia Arabes 2015년 2월 12일
Hi sir would like to ask, i inputted that codes but when i was about to close all the GUI, the song still plays on, and it needed to close everything(MATLAB) for it to stop. Can u help me with this problem sir?

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Audio I/O and Waveform Generation에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by