Text to Speech in ASP.NET with C#

Hi there,

I hope you guys had nice week, Its Saturday wasn't working but when I was having bath and thought of doing something interesting then I was working during the week on text to speech and thought of doing simplest and smallest code for text to speech. I'll go through in step by step in below section:

 

Step 1: Just create website.

 

Step 2: In the website just creates one page or you will already have default.aspx in side it, we have to create on text box in which person can write any text, also a button to click once you finish entering text and it will enable windows speech libraries. Please write following code to start with inside default.aspx.

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>Text to speach</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:TextBox ID="txtspeech" runat="server"></asp:TextBox>
        <br />
        <asp:Button ID="clickToSpeech" runat="server" Text="Speech" OnClick="clickToSpeech_Click" />
    </div>
    </form>
</body>
</html>

 

Step 3: Right click to solution explorer of the visual studio and add reference of SpeechLibrary. In the reference dialog box select the COM tab and add the "Microsoft Speech Object Library" and click ok. Now you will see in the references folder of your solution explorer "SpeechLib".

 

Step 4: And in code behind of Default.aspx which is Default.aspx.cs file, copy the following code.

using System;
using SpeechLib;

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

 

Step 5: Now run the code

And enter the text that you want and hit speech then you will listen the text

 

It was good weekend day for me to write little bit of brief explanation of text to speech.

If you like article, please don't forget to share or like this article.

Thank you

4 comments on “Text to Speech in ASP.NET with C#”

  1. Gravatar of rolex replica  rolex replica
    Posted Tuesday, December 4, 2012 at 7:32:48 AM

    In the website just creates one page or you will already have default.aspx in side it.

  2. Gravatar of replica watches  replica watches
    Posted Tuesday, December 4, 2012 at 7:33:15 AM

    And enter the text that you want and hit speech then you will listen the text.

  3. Gravatar of kolana  kolana
    Posted Saturday, June 1, 2013 at 7:26:01 AM


    The program is good. but i shows the on this part:

    txtspeech.Text.Trim()

  4. Gravatar of sanjeev  sanjeev
    Posted Friday, October 11, 2013 at 5:29:55 AM

    this code is nice, but for me it's working on localhost, but when I upload the page over the sever it do nothing.

Post a comment