Audio from text in app designer input box?

조회 수: 2 (최근 30일)
Allison Carey
Allison Carey 2018년 11월 9일
답변: Allison Carey 2018년 11월 13일
Hi everyone,
As of right now, I have a MATLAB app designer app that has an input screen where whoever runs the app is able to type whatever they want into it and click a button to display their text on the panel that becomes visible (covers the input box). Is there a way to code in that the computer will speak the text they type into the input box when the "enter" button is pressed? I found this code (not mine) online and am thinking there is a way to add parts of this to my code and make the audio work.
% Program to do text to speech.
% Get user's sentence
userPrompt = 'What do you want to say to the patient?';
titleBar = 'Text to Speech';
defaultString = 'Type in a message you want the patient to hear!';
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);
Thanks in advance!

채택된 답변

Allison Carey
Allison Carey 2018년 11월 13일
Figured it out actually!
Just had to add the lower part of the clip of code I attached:
caUserInput = char(app.finished_message.Value); % Convert from cell to string.
NET.addAssembly('System.Speech');
obj = System.Speech.Synthesis.SpeechSynthesizer;
obj.Volume = 100;
Speak(obj, caUserInput);
into the callback function for the "DONE" button - the button they would press to display their input text.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Get Started with MATLAB에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by