Playing with sapi.dll

Written by stevey on July 27th, 2010

With Microsoft’s Speech Library, it is extremely easy to add voice to your .Net application.

I created a small Console app in VS2010 and here were the steps I took:

  1. Add reference to sapi.dll, which was found in my computer’s C:\Program Files\Common Files\Microsoft Shared\Speech (Windows XP SP2)
  2. Import the Speech type library namespace
  3. Instantiated a SpVoice and called the Speak method; that was all.
Sample codes:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SpeechLib;
namespace ComInterop
{
class Speech
{
public static void SayThis(string words)
{
SpVoice voice = new SpVoice();
voice.Speak(words, SpeechVoiceSpeakFlags.SVSFDefault);
}
}
static void Main(string[] args)
{
////speech library
Console.WriteLine(“Type a few words to speak”);
string words = Console.ReadLine();
Speech.SayThis(words);
Console.ReadKey();
}
}

 

 

Leave a Comment