MATLAB: How to get the code to speak with a voice

MATLABtext to speech

Im working on a big program and one of the few things I want it to do is speak. Does anyone have an idea. For example if my code is:
x=input('Hello','s');
if strcmpi(x,'Hello')
fprintf('Hello sir')
end
I want the hello sir to come out with a voice.

Best Answer

For text to speech, if you have Windows, you can try my demo program:
% Program to do text to speech.
% Get user's sentence
userPrompt = 'What do you want the computer to say?';
titleBar = 'Text to Speech';
defaultString = 'Hello World! MATLAB is an awesome program!';
caUserInput = inputdlg(userPrompt, titleBar, 1, {defaultString});
if isempty(caUserInput)
return;
end; % Bail out if they clicked Cancel.
caUserInput = char(caUserInput); % Convert from cell to string.
NET.addAssembly('System.Speech');
obj = System.Speech.Synthesis.SpeechSynthesizer;
obj.Volume = 100;
Speak(obj, caUserInput);