Text to Speech Windows Form Application and Save Audio as .wav file using C#

Bangalore: Hi Friends today we are going to discuss about a Desktop Application developed using Windows Forms and C#.
Development Tool :Visual Studio 2010
So create a Windows Form Application project under C# using Visual Studio

And Design your form Like this One TextField with Multiline Property as True.
And three buttons one for Speak another for Clear and another for saving your data in voice format.
Now right click references and Include "System.Speech " reference to your project.
Double click on three Buttons and code behind write this codes.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Speech.Synthesis;

namespace TextToSpeech
{
    public partial class Form1 : Form
    {
        SpeechSynthesizer voice = new SpeechSynthesizer();
        public Form1()
        {
            InitializeComponent();
        }

        #region
        private void button1_Click(object sender, EventArgs e)
        {
            voice.Speak(textBox1.Text);
        }
        #endregion
        #region
        private void button3_Click(object sender, EventArgs e)
        {
            SaveFileDialog savefile = new SaveFileDialog();

            savefile.Filter = "All files (*.*)|*.*|wav files (*.wav)|*.wav";
            savefile.Title = "Save  file";
            savefile.FilterIndex = 2;
            savefile.RestoreDirectory = true;

            if (savefile.ShowDialog() == DialogResult.OK)
            {
                FileStream files = new FileStream(savefile.FileName, FileMode.Create, FileAccess.Write);
                voice.SetOutputToWaveStream(files);
                voice.Speak(textBox1.Text);
                files.Close();
            }
        }
        #endregion
        #region
        private void button2_Click(object sender, EventArgs e)
        {
            textBox1.Text = "";
        }
        #endregion
    }
}


We will create an object of SpeechSynthesizer and using that we will convert to Text To Speech using FileStream  and speech object we will save text as Audio.

K now we are going to make it as .exe set up file.
right click on your solution and add new project as per the screen shot.
Right click on your new setup project Click on View>FileSystems
Then right click on your Application Folder and add Project Output.
now go and Build your new project.you can see your Setups Inside your New Project Folder Install it and check it out.
Here I have given Sample Setup Download
Write to us If you are facing any difficulties.

2 comments:

  1. How to convert audio file in text?(Windows forms c#)

    ReplyDelete
    Replies
    1. You have to use SpeechRecognitionEngine for that..
      http://msdn.microsoft.com/en-us/library/system.speech.recognition.speechrecognitionengine.aspx

      http://msdn.microsoft.com/en-us/library/system.speech.recognition.speechrecognitionengine.speechrecognized.aspx

      http://msdn.microsoft.com/en-us/library/system.speech.recognition.speechrecognitionengine.speechhypothesized.aspx

      Delete