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:
- Add reference to sapi.dll, which was found in my computer’s C:\Program Files\Common Files\Microsoft Shared\Speech (Windows XP SP2)
- Import the Speech type library namespace
- 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();
}
}