Archive for tag: Text to Speech

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="">
    <title>Text to speach</title>
    <form id="form1" runat="server">
        <asp:TextBox ID="txtspeech" runat="server"></asp:TextBox>
        <br />
        <asp:Button ID="clickToSpeech" runat="server" Text="Speech" OnClick="clickToSpeech_Click" />


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);


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