Tech Note 824 - Using Microsoft .NET DLLs in Your Application Server Script
Tech Note 824 - Using Microsoft .NET DLLs in Your Application Server Script
All Tech Notes, Tech Alerts and KBCD documents and software are provided "as is" without warranty of any kind. See the Terms of Use for more information.
Topic#: t002615
Created: February 2012
Introduction
This Tech Note provides an example of using a Microsoft .NET dll in your Application Server Script. Our example uses the Microsoft
System.Speech.dll (Text to Speech library) to annunciate text. You can use this Tech Note as a guideline for using methods from any custom or
Microsoft .NET dll in your Application Server script.
Several 3rd party libraries are available for annunciating text. Two such libraries (SDKs) from Microsoft are the Directx sdk and
SpeechSynthesizer class from .NET 3.0 and later. For this Tech Note, we use the System.Speech.dll SpeechSynthesizer class from .NET 3.0 to
annunciate text.
Application Version
Application Server 3.1 SP3 P01 (the script was tested on the GR node).
1. Edit the UDTextToSpeech Object Instance by clicking on the Scripts tab, then clicking the Fx symbol to open the Script Function Browser.
2. Confirm that the System.Speech.Synthesis.SpeechSynthesizer class appears in the script function browser.
• saySomethingText: String, configure a default text which will be then Annunciated(played back) when script runs.
• speakerRate: Integer, default value 1. When this value is increased greater than 1, the text is spoken at a faster rate.
• speakerVolume: Integer, default value 100. This is full volume. To decrease the speaker volume, change this value to something less
than 100.
2. Configure the Expression and Trigger type for this script, so that the script will execute when the boolean bTalkNow is set to true.
3. Type the following script into the script editor. You can copy/paste from the section below.
me.bTalkNow = false;
Line #4 and Line#5 set up the properties: speaker Rate and speaker Volume.
Line #6 sets up the text to be spoken. The SpeakAsync method is used which executes Acynchrousnously.
Line #7 sets the boolean btalkNow to false. This is so that the text is spoken only once (it would be annoying to hear the text repeat over
and over until the object undeployed!)
After configuring above, you should see the following in the Scripts editor (Figure 12 below).
1. For testing, open Object Viewer and add the following attributes into the Watch List window:
2. Set the boolean bTalkNow value to true. You should now hear the text configured in the string UDA – saySomethingText.
3. You can also change the Text, speakerRate and speakerVolume at runtime using the Watch List window.
References
http://msdn.microsoft.com/en-us/library/system.speech.synthesis.speechsynthesizer(v=VS.90).aspx
http://www.codeproject.com/Articles/28725/A-Very-Easy-Introduction-to-Microsoft-NET-Speech-S
P. Kulkarni
Tech Notes are published occasionally by Wonderware Technical Support. Publisher: Invensys Systems, Inc., 26561 Rancho Parkway South, Lake Forest, CA 92630. There is also technical
information on our software products at Wonderware Technical Support.
Back to top
©2012 Invensys Systems, Inc. All rights reserved. No part of the material protected by this copyright may be reproduced or utilized in any form or by any means, electronic or mechanical,
including photocopying, recording, broadcasting, or by anyinformation storage and retrieval system, without permission in writing from Invensys Systems, Inc. Terms of Use.