Microsoft Agent ActiveX Control in VB A Cool Intro’ - R.Purushothaman This article touches Microsoft Agent ActiveX control up to the basic. This article is written assuming that the reader is familiar with Visual Basic 6 programming. R U bored of simple Visual Basic Forms? If the answer is yes, then you are the right person to eat this. You might have seen many characters in your life. Now let me show my hands to some characters in your desktop. Thanks to Microsoft Agent ActiveX control and API (Application Programming Interface), we can make animated characters work for you. You can program a ‘Genie’ or a ‘Parrot’ or a ‘Virgin Girl’ to wish for you when you start your application and respond to your voice commands. Microsoft Agent’s services are easy to access from the programming languages that support the ActiveX control interface, and Microsoft visual basic is one of such programming language. What is Microsoft Agent Control? Microsoft Agent is a set of programmable software services that supports the presentation of interactive animated characters within the Microsoft Windows interface. Developers can use characters as interactive assistants to introduce, guide, entertain, or otherwise enhance their Web pages or applications in addition to the conventional use of windows, menus, and controls. It is implemented as an OLE Automation (Component Object Model, COM) server. Microsoft agent is an ActiveX control which can be used to display and animate some Characters. Those characters can be animated and can respond to your voice and mouse commands. The animation and the movement of the character’s image are controlled by the Microsoft Agent’s Animation service. Basically, an animation is nothing but the sequence of frames that are timed for their display. System Requirements To work with Microsoft® Agent ActiveX™ technology, you need some of the following components along with Windows Operating System. 1. Ms -Agent core components 2. Lernout & Hauspie Truvoice Text – To – Speech Engine 3. Microsoft command and control speech engine. These are the integral components of Microsoft Agent SDK (Software Development kit) which comes with Microsoft Visual Studio 6.0. It’s available in all Microsoft Windows version. If you don’t have them, download from Internet. The SDK comes with 3 characters (Merlin, Genie and Robby). There are myriad of other characters available on Internet. They are available at www.microsoft.com/msagent. Search your computer for .ACS File. More tools Along with the agent core components, developers can download the following tools from the same above mentioned site. • • MS-Agent Character Editor (ACE) helps you to create your own custom characters to use in your applications. Microsoft Agent Linguistic Information Sound editing tool helps to enhance the sound capabilities of the character and to produce high quality lip synching for the character. Where is the Ms Agent Control? There are some default controls present in the toolbox of the Visual Basic 6 Environment. The Microsoft Agent control is not present in that intrinsic control list and so the control must be added to the Visual Basic project through the Components dialog box. To do so, 1. First create or open a new Visual Basic Form by clicking File New Project and select Standard EXE from the available list 2. To add the Ms Agent control to the toolbox click Project Components (or) press CTRL + T and then select Microsoft Agent Control 2.0 from the available list 3. Now you can see that a new control is added to the Visual Basic Toolbox. Double click that Control icon in Toolbox to add that control to the form. To keep this article simple to understand let’s keep aside the architectural design of Microsoft Agent services and COM server. Now let us see the programming face (phase). Loading a Animated Character Before animating a character we must load that character to our application. To load the character’s data, Load method of the Agent ActiveX control is used. Microsoft agent control can support two types of animated character data. They are • By HTTP service This is the separate file format that can be accessed via HTTP server. These files with extension .ACF & .ACA can be used in designing Microsoft Agent enabled Interactive web pages. • By Simple File Access This is the single structured file format (.ACS). These files are stored locally in the disk. Please note that, in this entire section I will use only .ACS format for making the reader feel easy. In the code 1 below, we have loaded the Peedy animated character which looks like a parrot. The first argument given to the Load function is Code 1 the Character ID of the Private Sub Form_Load () character being loaded. ‘Load Animation Character Agent1.Characters.Load "Agent", "Peedy.acs" It uniquely identifies the current agent character ‘To Show the Agent on Screen from other loaded Agent1.Characters.Item ("Agent").Show characters. End Sub The second argument is the character data file. In this example Peedy character is used and so the data file for Peedy character file (Peedy.acs) has been specified. The character is loaded automatically from the C:\Windows\MsAgent\Char\ folder. If the file is present any where then specify the filename along with the path as “C:\Agent\Peedy.acs” or if you want load the default character don’t include the second argument. Example: Agent1.Characters.Load "Agent" If you copy the code 1 in the Visual Basic application, and run it, you may notice that an animated parrot in front of you. Before executing the applications make sure that the path name of Peedy.acs is correctly specified. If not, use the appropriate path name in the second argument A Microsoft Agent control can load only one Character at a time; however we can load multiple instances of the same or different characters using separate Microsoft Agent Controls. In this case, to identify the desired Agent Character, Character ID is used. Displaying the Character After loading the character’ data we must use the Show method of the Agent control to show the loaded animated character. Note that when using the Show method we have used the Agent control’s Character ID as the argument to the Item (Code 1). Let them Speak & Think The Speak method enables you to program the character to speak the text, automatically lip-syncing the output. Specify the text to be spoken by the character as the Code 2 argument to the Private Sub cmdSpeak_Click () Speak method. Agent Agent1.Characters("Agent").Speak "Hello" supports textual Agent1.Characters("Agent").Think "R U Mad?" captioning of Speak End Sub method using a cartoon word balloon. According to the text, the lip movement of the character is synchronized. Look for the Code 2. You can also include vertical bar characters (|) in the Text parameter to designate alternative strings, so that the Agent Control randomly chooses a different string each time it processes the method. Look this code, Agent1.Characters("Agent").Speak "Hello|Welcome|Warm Entry" To generate voice output, a compatible TTS (Text To Speech) engine must be installed. If TTS engine is not installed in your system, no voice is heard and only the text is displayed. You might have noticed the method Think in the Code 2. The Think method is used to display the specified text for the specified character in a "thought" word balloon. See the thinking “R U Mad?”. Playing the Animation When the character frame is loaded we can animate the character by using the Play method of the Agent control. You can use the Play method, specifying the name of an animation, to play that animation. Please note that animation names are specific to a character definition. Agent1.Characters ("Agent").Play "Search" This line of code makes the agent character to play the search animation in the desktop. To get a list of all animation names supported by the character AnimationNames property is used. It’s an array of all animation names. Just look and observe the Code 3. This Visual Basic codes loads the Merlin character and then show it on the window for you. Moreover, it populates the combo box (Combo1) with the animation names that are available Code 3 Private Sub Form_Load () with the Merlin Dim AniNames As String character and Agent1.Characters.Load "Agent", "Merlin.acs" then plays the Agent1.Characters.Item ("Agent").Show “Search” For Each AniNames In _ animation of the Agent1.Characters("Agent").AnimationNames Merlin character. Combo1.AddItem AniNames If you try to play Next an animation Cpmbo1.ListIndex = 0 which is not supported by a Agent1.Characters ("Agent").Play "Search" End Sub character, Visual Basic generates an error. So be cautious that you are specifying the correct animation name for the loaded character. Some common animations that most of the characters can perform are Show, Hide, and Alert. Positioning the character When the Agent character is loaded at run time, the character is positioned at the screens top left corner. The loaded character can be moved within the screen using Top, Left (property) and MoveTo (method). • Top property returns or sets the top edge of the character. • Left property returns or sets the left edge of the character. • MoveTo method moves the character to the specified location. The Top and Left properties are always expressed in pixels, relative to screen origin. Look down for the code to reposition the character at run time. Agent1.Characters("Merlin").Top = 40 iLeft = Agent1.Characters("Merlin").Left Agent1.Characters("Merlin").MoveTo 150, 230 Hiding the character To hide the loaded character, the Hide method comes to the help. When you hide the character, the character disappears from the desktop. When the voice recognition feature of the character is enabled, you can call back the hidden character by just speaking the character’s name in the microphone. Agent1.Characters ("Merlin").Hide The above line of code hides the character with the Character ID “Merlin” from the screen. Setting Balloon styles As I said, Speak and Think method displays the text using a cartoon word balloon. A character's initial word balloon styles are defined when they are compiled using Microsoft Agent Character Editor. You can access the properties for a character's word balloon through the Balloon object, which is a child of the Character object. The properties that can be overridden are FontCharSet, FontName, FontSize, Style and Visible The user can’t set the values for other properties. Those read only properties are BackColor, BorderColor, Enabled, CharsPerLine, FontUnderline, ForeColor, FontStrikeThru, NumberOfLines, FontBold, FontItalic. I hoped you enjoyed this article and feel free to drop in your queries, suggestions and criticisms to mailtopuru@yahoo.com References: www.microsoft.com/msagent For more topics, use your favorite search engine.