Unable to play .wav file
2 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
采纳的回答
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
2011-9-1
Before the textscan:
words = lower(words);
words(~ismember(words, ['a':'z' ' '])) = ' ';
then go ahead with the textscan
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 Center 和 File Exchange 中查找有关 Audio and Video Data 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!