Andri Yadi

Butterfly Effect
See also: Other Geeks@INDC

February 2008 - Posts

Bina ISV | Silverlight & AJAX in Action

I've never presented or delivered a talk inside cinema studio before. This time, Feb 28, 2008, I deliver a talk entitled Silverlight & AJAX in action at Bina ISV event entitled Next Generation Web. The event is held inside Blitz Mega Plex cinema studio.

My presentation slide can be downloaded at: http://dycode.com/files/folders/binaisv/entry116.aspx

These are some photos

100_0648

Me, presenting Silverlight & AJAX in Action

100_0650

The audiences

 

Other speakers

100_0654

Narenda Wicaksono presenting Microsoft Solution for Windows Based Hosting

100_0653

Agung Riyadi presenting ASP.NET 3.5 Improvement and IIS 7.0

Share this post: | | | |
Speak Up Your Email - An Outlook Add-in using VSTO & Speech API

This is one of the live coding demo that I showed in OBA with VSTO v3 training at PT. Astra Honda Motor. Please refer to this posting to read the details about the training.

What I'm about to talk in this posting is an Outlook Add-in that can speak up your email, it's like you have a personal assistant that can read your email with nice intonation like human being. I'm gonna share with you in this posting about how to build it. It's simple yet fun.

To be able to speech an email message or any string, you need a Text-to-Speech (TTS) library. I won't discuss how to build it here, it's beyond my expertise, at least for now, so I'm gonna use existing one. Many free TTS or Speech Synthesizer available out there, such as: Microsoft Speech API SDK, Festival, festvox, FreeTTS, etc. For the sake of simplicity in term of getting the library and coding with managed code like VSTO, I use Microsoft Speech API (SAPI). If you use Windows XP or VISTA, SAPI has been available for free. The latest version is SAPI 5.3 delivered with Windows Vista, while Windows XP has SAPI 5.1.

To work with SAPI from managed code, you have two options: using native interfaces by using Interop to COM of SAPI 5.3, or using managed interface to SAPI 5.3 those are available in System.Speech* namespaces introduced in .NET Framework 3.0 or later. In this posting I use managed interface to simplify the code. Please refer to resources below for more details about Microsoft SAPI.

OK, lets get back to our topic. The steps to build the Add-in are:

1. Create New Project. On Project types list select Office, then select Outlook 2007 Add-in on templates list. Name the project as SpeakUpYourEmail or whatever you want, then click OK.

image

In your solution, you'll have these files. The ThisAddIn.cs file will be automatically opened.

image

2. To add Speech capability in your project, add reference to Microsoft Speech managed library. Right click to project name, click Add Reference, and at the Add Reference dialog select System.Speech.

image

 

3. Coding ThisAddIn.cs

The complete code for ThisAddIn.cs. Hopefully, it's self describing

using System;
using Outlook = Microsoft.Office.Interop.Outlook;
using System.Speech.Synthesis;
 
namespace SpeakUpYourEmail
{
    public partial class ThisAddIn
    {
        private SpeechSynthesizer synth;
        public SpeechSynthesizer Synthesizer
        {
            get { return this.synth; }
        }
 
        private void ThisAddIn_Startup(object sender, System.EventArgs e)
        {
            //Create new instance of SpeechSynthesizer
            synth = new SpeechSynthesizer();
            //Select Anna voice, more sexy and good intonation. 
            //Only available in Windows Vista.
            synth.SelectVoice("Microsoft Anna");
        }
 
        private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
        {
            if (synth != null)
            {
                synth.SpeakAsyncCancelAll();
                synth.Dispose();
                synth = null;
            }
        }
 
        public void StopTalking()
        {
            if (synth != null)
            {
                synth.SpeakAsyncCancelAll();
            }
        }
 
        public void StartTalking()
        {
            //Get the Explorer displaying mail list
            Outlook.Explorer activeExplorer = Application.ActiveExplorer();
            //Get the first selection of mails in mail list, cast it to MailItem
            Outlook.MailItem selectedMailItem = activeExplorer.Selection[1] as Outlook.MailItem;
 
            if (selectedMailItem != null)
            {
                String msgBody = selectedMailItem.Body; //get the mail body
 
                synth.SpeakAsyncCancelAll(); //First, cancel all speak
                synth.SpeakAsync(msgBody); //Then, speak it!!
            }
        }
 
        #region VSTO generated code
        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InternalStartup()
        {
            this.Startup += new System.EventHandler(ThisAddIn_Startup);
            this.Shutdown += new System.EventHandler(ThisAddIn_Shutdown);
        }        
        #endregion
    }
}

 

4. Add ribbon to place Speech control, such as button to start/stop speaking.

Right click to project name, Add New Item, select Ribbon (Visual Designer) template, name it DefaultRibbon.cs (or whatever you want), and click OK.

image

To control where the ribbon should be displayed in Outlook, select ribbon, then at Properties change RibbonType to whatever you want.In this case I choose Microsoft.Outlook.Mail.Read, so the ribbon will be displayed when you read an email in full read mode.

image

Add a button control to ribbon and set the properties like shown below

image

 

5. Code the ribbon

The complete code for ribbon:

using System;
using Microsoft.Office.Tools.Ribbon;
using System.Speech.Synthesis;
 
namespace SpeakUpYourEmail
{
    public partial class DefaultRibbon : OfficeRibbon
    {
        public DefaultRibbon()
        {
            InitializeComponent();
            this.Close += new EventHandler(DefaultRibbon_Close);
            this.buttonSpeech.Click += new EventHandler<RibbonControlEventArgs>(buttonSpeech_Click);
        }
 
        private void DefaultRibbon_Load(object sender, RibbonUIEventArgs e)
        {
        }
 
        private void DefaultRibbon_Close(object sender, EventArgs e)
        {
            //Stop speaking when the ribbon (reading mode) is closed
            Globals.ThisAddIn.StopTalking();
        }
 
        private void buttonSpeech_Click(object sender, RibbonControlEventArgs e)
        {
            //ThisAddIn methods & properties are accessible via Globals
            //Check SpeechSynthesizer state
            if (Globals.ThisAddIn.Synthesizer.State == SynthesizerState.Speaking)
            {
                //If it's speaking, stop it and change the button label
                Globals.ThisAddIn.StopTalking();
                buttonSpeech.Label = "Read it!";
            }
            else
            {
                //If it's paused or ready, start speaking 
                //and change the button label
                Globals.ThisAddIn.StartTalking();
                buttonSpeech.Label = "Stop!";
            }
        }
    }
}

 

6. Build the solution. If nothing goes wrong, debug it by pressing F5.

Then Microsoft Outlook will be appeared. Open your Inbox, double click to an email and Message dialog will be displayed. You'll notice there is a Add-Ins tab. Click it and you'll find Read it! button. Click the button, and you'll hear a nice sexy female voice reading your email.

image 

If the email to read is long enough, you can stop the reading by clicking that button again or just close the message dialog, the speaking will be stopped automatically. What a pleasure having a sexy assistant reading your email huh! :)

As a conclusion of this posting, VSTO allows us to build unlimited possibility of OBA, from the simple one like example in this posting, until the complex ones like my company product PortMan. For more details about VSTO, go to: VSTO Developer Center

You can download the VS 2008 solution of this example at: http://dycode.com/files/folders/codesamples/entry92.aspx

Have a nice try and let me know your comments.

 


Microsoft Speech API resources:

Exploring New Speech Recognition And Synthesis APIs In Windows Vista

System.Speech code samples

Speech Synthesis Example

Developing for Speech

A Fun Windows Form Application

 
Share this post: | | | |
Training of Office Business Application (OBA) with VSTO v3 - Astra Honda Motor

On Valentine's day, Feb 14, 2007 ago, when I'm supposed to spend time with special one, instead I'm asked by Microsoft Indonesia to deliver a training at PT. Astra Honda Motor (AHM) Training Center, Jakarta. The topic is Office Business Application (OBA) using VSTO v3 & Visual Studio 2008. Since the scope of VSTO is quite large to be delivered within one day, I emphasize the training to VSTO for Microsoft Outlook and Microsoft Excel.

The training outline:

VSTO Overview

In this part, I describe:

  • What is Microsoft Office System, especially 2007 Microsoft Office System and why we need to extend Office System to develop Office Business Application
  • What is Visual Studio Tools for the Microsoft Office System (VSTO) and how we can possibly develop OBA with VSTO
  • Roadmap of VSTO started from VSTO 2005 until VSTO v3 introduced in Visual Studio 2008
  • VSTO project templates, Document Level vs Application Level development, Office Primary Interop Assemblies (PIA), etc

VSTO for Outlook

Then it's time to explain deeper into VSTO for Outlook.

  • First thing first, I explain what we can possibly build using VSTO for Outlook
  • Outlook Object Model, some high level classes those need to be understood before building Outlook solutions using VSTO
  • Outlook Ribbon customization
  • Since it's impossible to learn all VSTO for Outlook features within a half day training, I explain them by samples.

VSTO for Excel

Quite same as Outlook, in this part I explain what we do with VSTO for Excel, Excel Object Model, and some samples to quickly grab the concepts of VSTO for Excel.

For more details about the training material, you can download the slide at: http://dycode.com/files/folders/dotnet_training/entry91.aspx

I also do live coding to give some demos to be followed by trainees. One of the demo that is simple yet fun to talk about is an Outlook Add-in that can speak up your email, it's like you have a personal assistant that can read your email with nice intonation like human being. I'm gonna share with you in this posting about how to build it.

 

These are some photos taken during and after the training.

The good looking trainer :) and the slide

100_0319

100_0330

The trainees

100_0324

Explaining how to consume web service from Excel

100_0332

Iman Harmaen and I, smoking in smoking room, bad example :P

100_0328

Reki, Ms. Melinda, Mr. Theo, me, and the trainees (forgot the names)

100_0352

That's it. Enjoy the photos :) and learn the presentation slide. Hopefully help you to get started with VSTO.
Refer to this posting attachment to get the demo code.

Share this post: | | | |
Posted: Feb 18 2008, 03:26 AM by andriyadi | with 1 comment(s)
Filed under: ,