Tuesday, January 22, 2008

Text to Speech Applications in C#


Microsoft always provides simple solutions for complex problems.

Microsoft introduced Speech SDK 5.1 to handle text to speech applications. You can download speech SDK from below microsoft Site.

http://www.microsoft.com/downloads/details.aspx?FamilyId=5E86EC97-40A7-453F-B0EE-6583171B4530&displaylang=en

After installed SpeechSDK51.exe, you need to do the following steps to create speech application.

1. Open new C# Web Application.
2. Add the Reference Microsoft object speech application
3. Add the namespace : using SpeechLib;
4. You should refer the below api for this application.

[DllImport("winmm.dll", EntryPoint = "mciSendStringA", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)] private static extern int mciSendString(string lpstrCommand, string lpstrReturnString, int uReturnLength, int hwndCallback);

Find the simple source code for speech application in web.

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Microsoft.VisualBasic.Devices;
using Microsoft.VisualBasic;
using System.Runtime.InteropServices;
using SpeechLib;

public partial class _Default : System.Web.UI.Page
{
[DllImport("winmm.dll", EntryPoint = "mciSendStringA", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
private static extern int mciSendString(string lpstrCommand, string lpstrReturnString, int uReturnLength, int hwndCallback);

protected void Button4_Click(object sender, EventArgs e)
{
SpVoice spVoice = new SpVoice();
SpeechVoiceSpeakFlags svsp = new SpeechVoiceSpeakFlags();
spVoice.Speak(this.TextBox1.Text.ToString(),svsp);
}
}

No comments: