How can I get my code to speak with a voice

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.

3 件のコメント

Sylvain KPEKOU
Sylvain KPEKOU 2018 年 12 月 8 日
defaultString = 'Hello Sir';
NET.addAssembly('System.Speech');
obj = System.Speech.Synthesis.SpeechSynthesizer;
obj.Volume = 100;
Speak(obj, defaultString );
Image Analyst
Image Analyst 2018 年 12 月 8 日
Yes, that SpeechSynthesizer answer was already given below. Perhaps you didn't scroll down to the answers section to see it.
prathima k
prathima k 2019 年 6 月 6 日
How can i store the speech in a variable and produce audio output in raspberry pi 3

サインインしてコメントする。

 採用された回答

Image Analyst
Image Analyst 2017 年 7 月 31 日

1 投票

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);

8 件のコメント

Rainaire Hansford
Rainaire Hansford 2017 年 8 月 29 日
Wow that is amazing is there a way where I can change the voice from male to female.
Rainaire Hansford
Rainaire Hansford 2017 年 8 月 29 日
also I have a code like this where if I type in a input it will respond with an out put for example:
x=input('Password','s');
if strcmpi(password,'hello')
fprintf('Password accepted.')
end
I want say "Password" and when I type in or speak it "hello" i want it say "password accepted". Do you have any idea how to get that to happen?
Walter Roberson
Walter Roberson 2017 年 8 月 29 日
You can use the SelectVoice method to choose a different voice.
To have it output 'Password accepted.', use
Speak(obj, 'Password accepted.')
To be able to speak "hello" and have it understood, then you need some completely different software: you would need speech recognition software. There are some a number of postings about that, and there are some contributions such as https://www.mathworks.com/matlabcentral/fileexchange/27276-speech-recognition or https://www.mathworks.com/matlabcentral/fileexchange/36398-speech-recognition-using-mfcc-and-lpc
Rainaire Hansford
Rainaire Hansford 2017 年 11 月 29 日
Hey Walter sorry its been a long time. I tried to make code above work. but it didn't seem recognize the code
speak(obj,'password accepted')
I tired:
obj=input('hello');
speak(obj,'password accepted')
So im not sure how I should go about this
Walter Roberson
Walter Roberson 2017 年 11 月 29 日
NET.addAssembly('System.Speech');
obj = System.Speech.Synthesis.SpeechSynthesizer;
obj.Volume = 100;
speak(obj, 'password accepted')
Edwin Cortez
Edwin Cortez 2022 年 4 月 11 日
Awesome. The Speak() function worked. Thank you.
kim
kim 2022 年 12 月 4 日
@Edwin Cortez can I see your code please
Image Analyst
Image Analyst 2022 年 12 月 4 日
@kim my Answer and several of the comments below it have code in them. Did you overlook the code? It's there.

サインインしてコメントする。

その他の回答 (2 件)

Stephen23
Stephen23 2017 年 7 月 24 日
編集済み: Stephen23 2017 年 7 月 25 日

1 投票

There is nothing built-in. Try downloading these:
Note that some rely on third-party apps or objects, and might only work on some versions of MATLAB. I know that at least some of them work, because I remember playing with them a year or two ago.

2 件のコメント

Rainaire Hansford
Rainaire Hansford 2017 年 7 月 30 日
Are theses like add-on for Matlab?
Walter Roberson
Walter Roberson 2017 年 7 月 30 日
The File Exchange contains MATLAB code (and possibly C or C++ code) that has been written by volunteers and made available for general use.
Some of the contributions for Text To Speech also need additional software packages beyond that.

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeDeep Learning Toolbox についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by