MATLAB: Speaking the time in the code or codes

MATLABtext to speaktext to speechtimewindows .net assembly

Hello MATLAB Community, again.
So I have a code where it speaks and shows the time, but I really want my code to speak the time I enter.
Right now I have:
res=input('','s');
if strcmpi(res,'What is the time')
NET.addAssembly('System.Speech');
obj = System.Speech.Synthesis.SpeechSynthesizer;
obj.Volume = 100;
Speak(obj, 'this is the time' )
fprintf('%s\n', datestr(now,'HH:MM:SS'))
s=-1;
k=1;
end
It speaks out but tells the current time. Is there a way to make it speak the time a user enters? Please provide an example. Thank you.

Best Answer

Hi,
If I have understood your question correctly, here is the corrected code that speaks the current time:
NET.addAssembly('System.Speech');
obj = System.Speech.Synthesis.SpeechSynthesizer;
obj.Volume = 100;
Speak(obj, 'this is the time' )
% If no need to display the time, then just to remove it.
Speak(obj, datestr(now,'HH:MM:SS'));
Good luck.