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:
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.
Have fun and happy Silverlighting!




December 1st, 2009 at 23:24
[...] This post was mentioned on Twitter by David Justice, fatihsenel. fatihsenel said: RT @DavideZordan: blogged: Having fun with Silverlight 4 Beta and the Speech APIs – http://bit.ly/4nBH6r #silverlight #in #fb [...]
December 2nd, 2009 at 00:55
Social comments and analytics for this post…
This post was mentioned on Twitter by DavidJustice: RT @davidezordan: blogged: Having fun with Silverlight 4 Beta and the Speech APIs – http://bit.ly/4nBH6r #silverlight #in #fb…
December 2nd, 2009 at 08:22
Great article.Do you think is possible to consume in Silverlight 4 speech recognition engine as well ?
Thanks
December 2nd, 2009 at 10:36
Yes, I think it’s possible using the automation bridge, I should give it a try
Thanks!
D
December 3rd, 2009 at 19:46
Is there something preventing this from working on Windows 7 64-bit? I am not receiving an error but I’m not hearing anything at all when the button is clicked.
December 3rd, 2009 at 22:10
Hi Dan,
I’ve tried the example on Windows 7 32/64 and all works well.
Hope this helps.
December 4th, 2009 at 15:52
Is there anything besides the SpeechSDK51.exe files that need to be loaded?
December 4th, 2009 at 16:09
No, you should be able to run it on Windows 7 without any SDK.
December 9th, 2009 at 13:24
[...] This post was Twitted by firojbd [...]
December 10th, 2009 at 22:11
David,
I am unclear on how to add the Microsoft.CSharp reference to the silverlight project. Even when setup for OOB I get an error that I cant reference Microsoft.CSharp.dll as it was not built against the Silverlight runtime when I try to add the reference. Thanks for any help.
December 10th, 2009 at 22:52
Hi Tim,
go to your Silverlight project, select “Reference->Add Reference->Browse” and locate Microsoft.CSharp.dll in the folder C:\Program Files\Microsoft SDKs\Silverlight\v4.0\Libraries\Client. Now you should be able to use the dynamic keyword.
HTH!
December 11th, 2009 at 16:16
Ahhhh thanks. I was trying to reference the same named DLL but in a different location. Nice blog by the way! Keep up the good work.
December 14th, 2009 at 20:37
Great blog! Can you please provide more examples of speech API and speech recogition? I’d like to see demos of speech recogition as well as hear you talk about automation bridge some. I don’t know what this automation bridge is unless your talking about the ActiveX COM dynamic keyword.
It would be great if you could tell what version of the speech API will work with this dynamic keyword. I’m assuming any COM object should work.
Thanks again for a great blog on SL4 and Speech API!!
December 14th, 2009 at 20:59
@Jerry: thank you for the kind words, I should post something new about this subject. In the meantime you can read these articles about Silverlight 4 beta and COM support:
- http://community.irritatedvowel.com/blogs/pete_browns_blog/archive/2009/12/08/Silverlight-4-COM-Support-and-32_2F00_64-bit-machines-_1320_-the-C64-Emulator.aspx
- http://www.wintellect.com/CS/blogs/jprosise/archive/2009/12/14/silverlight-4-s-new-com-automation-support.aspx
- http://victorgaudioso.wordpress.com/2009/12/03/new-silverlight-4-video-tutorial-how-to-use-the-com-api-to-open-word-in-an-out-of-the-browser-sl4-app/
Have a great day!
February 1st, 2010 at 08:33
Hi David,
I am getting the classic COMException (Class not registered (Exception from HRESULT: 0×80040154)while running this. I am running this on Windows 7 and I also checked the registery for the CLSID and also registered the sapi.dll but no luck ?
Any help would be appreciated . .
Thanks,
Jomit
February 8th, 2010 at 23:02
Hi Jomit, have you installed the sample as an Out of Browser application? I’ve tried it in several machines running Windows 7 and it works well, if I’ll encounter this problem I’ll let you know.
Thanks,
Davide
March 31st, 2010 at 03:36
Does it work on Windows Phone 7? Thanks!
March 31st, 2010 at 21:19
Hi Ivan,
no, this sample doesn’t work on Windows Phone 7.
July 24th, 2010 at 10:39
Hi Davide,
Nice article.
Is possible to invoke Speech Recognition Engine in SL 4.0?
Can we make a dictation software using SL4.0?
Your comments are appreciated…
July 24th, 2010 at 11:47
Hi Reejesh,
conceptually it’s possible to use the Speech Recognition engine using SL4 and COM but haven’t tried it yet.
Thanks!
July 26th, 2010 at 17:17
Hi Davide,
Thanks for your reply..
But I fear it’s conceptually only, since Speech Recognizer need System.Speech namespace to work.
Can we add this to WCF application in order to achieve this?
Your comments are appreciated.
Thanks again!
July 26th, 2010 at 18:48
Hi Reejesh,
if you want to use System.Speech you have to add a WCF service to interact with the Speech Recognizer.
Another approach can be the usage of the Speech SDK SAPI and SpInprocRecognizer via COM:
- http://msdn.microsoft.com/en-us/library/ee125663(v=VS.85).aspx
- http://www.microsoft.com/downloads/details.aspx?FamilyID=5e86ec97-40a7-453f-b0ee-6583171b4530&displaylang=en