Having fun with Silverlight 4 Beta and the Speech APIs

Silverlight 4 Beta is now available, one of the more interesting features is the ability to use Late Binding for automation APIs via the new dynamic keyword and the ComAutomationFactory class.

A great example is already available on the official http://silverlight.net site, using automation to control Excel in trusted applications.

With the same approach it’s possible to control any object exposed via COM so I’ve coded a (very simple) example to demonstrate the usage of the Speech APIs using this new automation bridge (thanks to Justin Angel on Twitter for the inspiration :) ).

Just reference in your Silverlight 4 Beta project the dll Microsoft.CSharp.dll contained in the SDK folder to enable the usage of the dynamic keyword.

Then enable elevated-trust by activating the Out of Browser mode and clicking on the “Require elevated trust when running out of browser” checkbox:

ElevatedTrustOOB

The code used is very simple, just create an instance of the COM object using the ComAutomationFactory.CreateObject() method:

dynamic speech = ComAutomationFactory.CreateObject("Sapi.SpVoice");

Then use the Speak method to make Silverlight speak (sorry, no code completion here, we’re using late binding):

speech.Speak("Hi Guys! This is Silverlight 4 Beta speaking!");

The complete Silverlight 4 Beta project is available for download here.

SpeechCapture

Have fun and happy Silverlighting!


22 Responses to “Having fun with Silverlight 4 Beta and the Speech APIs”

Leave a Reply