Tablets Vista and WPF - Part II
Well, in the first part, I said I was going to start working on getting it working with WPF/E Silverlight. All I realized was that it looked a little easier than I first thought. Anyway, I wanted to play with a few tweaks first.
So I added a few buttons. One to perform Recognitions. Another to Speak the text that was recognized if there was in fact any text recognized. There are a lot of possibilities in terms of productivity apps that you could make here. So let's say I was doing a little Janusian Thinking and figured I'd write the first thing that came to my mind...
I'd ink some text, then check the Title of my WPF form to make sure it worked. If it works correctly, the Form's Title will match what was scribbled, in the first case it does:
Cool, that worked. Now, I let my mind wander a little more, let me see if it can do something a little more complex:
Well, the first one was clearly correct, the second one though, LearnASP Six? Wrong Vowel for sure. But that's mainly b/c of my terrible handwriting, if I write it a little more clearly, it gets it right no problem (more on this later);
So first, I just create an System.Windows.Ink.InkAnalyzer object scoped for the class, instantiate it in the constructor, and use the following to Analyze the strokes. I create a property named TextToSpeak which I set after the recognition. This is used in the Speech portion of the application.
if (icMain.Strokes != null && icMain.Strokes.Count > 0)
{
azr.AddStrokes(icMain.Strokes);//Add strokes from the InkCanvas to the Analyzer
azr.Analyze(); //This coverts the strokes to text if possible
this.TextToSpeak = azr.GetRecognizedString();//If text was recognized, this is it.
this.Title = this.TextToSpeak;
}
To get the app to speak, it's laughably easy. Using the System.Speech namespace on Vista, it couldn't be easier:
SpeechSynthesizer sz = new SpeechSynthesizer();
sz.SpeakAsync(this.TextToSpeak);
Depending on how close your recognition gets to real language, you'll be very impressed by how well and how accurately the Speech Synthesizer works.
I have a form that doesn't lend itself well to screen shots unless it's shrunken down which I started working on to let you scribble away. When you're done, you can use Speech commands to open the file into your app and have it read back whatever you scribbled. There's a lot of software that already does this stuff for you, but it's pretty cool to use to familiarize yourself with some of these APIs.
This is a really basic intro to Recognitions and it gets a lot more involved than this if you want it to. As I add more features to the app, I'll illustrate them. My Homie Frank LaVigne has written quite a bit on this subject and his blog is a goldmine for finding more resources on Tablet.
To be honest, most of what I covered is extremely basic, so much so it's not even blog worthy if it weren't for the fact that, well, it's done in WPF. Until recently I never really used the WPF Inking features and for some reason, it never dawned on me there'd be specific Tablet Support. Once again, I was wrong and quite pleasantly surprised.
The more I tried digging into WPF/E Silverlight, the more I realized it was going to be a bit of a challenge to get everything to work the way I wanted. What I'm sort of looking to do is use a fixed set of recognizable gestures to control media - like Fast Forward with strokes, Record with a Circular stroke, Triangle for Play - you get the idea. But I need to spend some more time doing and less time talking about it, so off I go.