New Year Application using C#.NET

Objective

To develop a Windows application using the Microsoft Speech Object Library in C# .NET to wish a 'Happy New Year'.

Step 1. Go to 'Project' menu

Go to the 'Project' Menu -> Select 'AddReference'-> Click on the 'COM' tab.

Select 'Microsoft Speech Object Library' -> OK.

Com

Note. To use this COM component, we must include the 'using SpeechLib' namespace in the code.

Step 2. Design

Enter your name

Design the form as shown above with one Label, one TextBox, and three Buttons.

Step 3. Code

using System;
using System.Windows.Forms;
using SpeechLib;
namespace newyearapp
{
    public partial class newyearapp : Form
    {
        public newyearapp()
        {
            InitializeComponent();
        }
        string str1 = "wish you a happy and prosperous new year ", str2;
        SpVoice obj = new SpVoice();
        private void btnOK_Click(object sender, EventArgs e)
        {
            if (textBox1.Text.Trim().Length > 0)
            {
                str2 = str1 + textBox1.Text;
                obj.Speak(str2, SpeechVoiceSpeakFlags.SVSFDefault);
            }
            else
                obj.Speak(str1, SpeechVoiceSpeakFlags.SVSFDefault);
        }
        private void btnClear_Click(object sender, EventArgs e)
        {
            textBox1.Text = "";
        }
        private void btnExit_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}

Output

We will hear New Year's wishes.


Similar Articles