Speaking the time in my code or codes

조회 수: 1 (최근 30일)
Rainaire Hansford
Rainaire Hansford 2019년 5월 25일
댓글: Rainaire Hansford 2019년 5월 29일
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.

채택된 답변

Sulaymon Eshkabilov
Sulaymon Eshkabilov 2019년 5월 26일
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.
  댓글 수: 3
Sulaymon Eshkabilov
Sulaymon Eshkabilov 2019년 5월 28일
You are welcome! It is just a pleasure. Good luck.
Image Analyst
Image Analyst 2019년 5월 28일
Surprised you picked this answer as the best one since it does not speak the time the user entered with your input() function, like you asked for and like my answer below does. So if you're still wondering how to do that, see my solution.

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

추가 답변 (1개)

Image Analyst
Image Analyst 2019년 5월 26일
Try this. It works. Adapt as needed.
% Instantiate the speech .Net assembly (for Windows only - not Apple!!)
NET.addAssembly('System.Speech');
obj = System.Speech.Synthesis.SpeechSynthesizer;
obj.Volume = 100;
% Have the computer tell us the current time.
Speak(obj, 'This is the current time')
string2 = sprintf('%s', datestr(now,'HH:MM:SS'))
Speak(obj, string2)
% Now let the user enter something.
Speak(obj, 'Now it is your turn to enter a time')
string3 = input('Enter a time in the form HH:MM:SS : ', 's')
Speak(obj, string3)
  댓글 수: 1
Rainaire Hansford
Rainaire Hansford 2019년 5월 29일
Oh yours is cool too. I didnt see yours actually. Really I just wanted it to say the time. But I may use yours for setting a time, timer or alarm. Thank you.

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

카테고리

Help CenterFile Exchange에서 MATLAB Compiler SDK에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by