Sunday, August 30, 2009

SpeechLogger – output log messages in speech form

Last week in our team outing we saw the movie “Transformers: Revenge Of The Fallen”. I loved “Transformers” which was released in 2007, and automatically became a fan of this one too. For those of you who have missed the action, here is the link Transformers movie. Although not unique to this movie, the computer generated audio updates and notifications caught my attention. I was planning something similar for my ‘computer-agents’ (a dream I am working on in my free time), but the application of audio for debugging looked exciting. More importantly, it will make debugging fun.

Now with the Microsoft’s Speech synthesizer in its version 3.0, things are a lot simpler and faster to accomplish. Moreover, .NET is like a song, even if you don’t know the complete lyrics you can manage just by humming. You can find more information on Microsoft's speech technologies and R&D at Microsoft speech, or look for "SpeechSynthesizer” class in MSDN.

Audio deserves a special treatment, the following screencast will add the audio dimension:

Now let us have a look at the design of SpeechLogger: The base over which SpeechLogger sits is Microsoft Speech Synthesizer. Currently, the speech API is in version 3.0.

To develop custom functionality, I have written SpeechGenerator and SpeechQueue classes.

SpeechGenerator is the one that interacts with Microsoft’s Speech Synthesizer. It plays speech and the background sound (if there is any) in separate threads, and also away from your worker or UI threads. This ensures that using speech in your application won’t interfere with application’s core functionality.

Ok, SpeechGenerator is the core, so why do we need SpeechQueue? The reason for this is if you log many messages all might play at once. So to provide synchronous nature over asynchronous mode, we have SpeechQueue class. SpeechQueue maintains a queue of all the speeches to be played and enqueues items as and when SpeechGenerator notifies it.

You can use the SpeechLogger class to log speech messages. So, lets have a look at the code you will have to write to use SpeechLogger:

// set background sound for critical level
SpeechLogger.AttachBackgroundSound(LogLevel.CRITICAL, @"d:\warning.wav");

// log message
SpeechLogger.Log("Preparing to copy file.", LogLevel.INFORMATION);

Here is the code used for the demo-application:

(click the image if it is not clearly visible)

You will soon see a packaged version of SpeechLogger in both in-process and out-process form. The in-process version will be a simple dll that you can add as a reference to your project. Out-process will be a Windows service for speech logging. So till then, happy speech logging.

No comments: