"If at first you don't succeed; call it version 1.0" :-Unknown

Pages

Saturday, October 30, 2010

Text to speech in asp.net

step 1 : create new web site.
step 2 :  in the default.aspx page, copy the following code…

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
 <title>Text to speach</title>
</head>
<body>
 <form id="form1" runat="server">
 <div>
 <asp:TextBox ID="txtspeach" runat="server"></asp:TextBox>
 <br />
 <asp:Button ID="btn1" runat="server" Text="Speach" onclick="btn1_Click" />
 </div>
 </form>
</body>
</html>






Step 3: Right click on the solution explore of the visual studio and add reference
in the add reference dialog box select the COM tag and add “Microsoft Speech Object library” and click to ok.
Step 4 : In the Default.aspx.cs file, copy the following code……
using System;

using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using SpeechLib;
using System.Threading;

public partial class _Default : System.Web.UI.Page
{
 protected void btn1_Click(object sender, EventArgs e)
 {
 SpVoice objspeach = new SpVoice();
 objspeach.Speak(txtspeach.Text.Trim(), SpeechVoiceSpeakFlags.SVSFDefault);
 objspeach.WaitUntilDone(Timeout.Infinite);
 }
}

Step 5 : Run the code…
enter the text which u want to speech and then click to button, and listen the text…..





Have a nice day... 'N happy Coding :)

No comments: