Text to speech in asp.net with C#
Posted by Viral Sarvaiya on June 16, 2010
here i demonstrate the text to Speech conversion…
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…..
thanks…..
for more details : click here



viralsarvaiya said
Dear Shibin,
I test my application after you comment, its works fine,
can you please tell me, where you found difficultly?
Gaurav said
Thanx a lot, Sir. You really helped a lot.
mani said
Hi,
I did exactly the procedure u gave above….
but the application is not executing …..it is prompting errors(i did project in VS2010)
giving errors related to web stack trace…
pankaj tiwari said
Hi Sir,
Thax for your post. but how we change the voice, means how can we listen our text in indian accent
huda said
hi sir,
when I did step3: 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.
a pop up window comes says: converting the type library to a.NET has failed. no process associated to with this object
how to solve this problem?
Hamsa Ankamreddy said
Hiiiiii,
Have u deployed this application? Is it working good after deployment
viralsarvaiya said
i have created test application,
I have use in one my window base application and its working fine in it.
palak said
hello sir,
i find this blog from google
i also find intresting code from
http://codeprojectdownload.com/asp-net-2/convert-text-into-speech-in-asp-net/#.T0ScXIfXDZE
it may be Usefull for another user so i share this link here
Viral Sarvaiya said
Hi Palak,
Its nice link and thanks for sharing.
Kanna said
Hi When I deploy in the server, cannot hear from the client PC. But can hear the voice from the server pc