I want MATLAB to tell me when certain operations had completed on a program that involved long calculations. The solution is simple. Create a program called talk.m. The add the following code:
function talk()
Speak('testing speech capabilities of MATLAB')
end
function Speak(text)
NET.addAssembly('System.Speech');
speak = System.Speech.Synthesis.SpeechSynthesizer;
speak.Volume = 100;
speak.Speak(text);
end
This code works with MATLAB 2023b. A few previous versions of MATLAB returned the error “No voice installed on the system or none available with the current security setting.” even though I had all necessary components installed on my system, and I was executing with adequate permissions.
If the previous code does not work, the problem could be the file [matlabroot]/bin/[architecture]/MATLAB.exe.config which in my case was C:\Program Files\MATLAB\R2011b\bin\win64\MATLAB.exe.config.
This file, by default, contains the following text:
<configuration>
<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v4.0"/>
<supportedRuntime version="v2.0.50727"/>
</startup>
<runtime>
<loadFromRemoteSources enabled="true"/>
</runtime>
</configuration>
But speech synthesis is part of .NET 3.0, so the correct file should read:
<configuration>
<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v4.0"/>
<supportedRuntime version="v3.0"/>
<supportedRuntime version="v2.0.50727"/>
</startup>
<runtime>
<loadFromRemoteSources enabled="true"/>
</runtime>
</configuration>
After that, MATLAB sings ๐