deepender singla

deepender singla

  • NA
  • 113
  • 75.4k

Text toSpeech

Jul 28 2011 11:37 AM
I am working on this code in which i am creating grammar then giving speech input to it , the code is working fine,

I want to add something in code like if a write this in string "hello world"in my code; my computer speaks that. how i can do that there must be some command but i am not able to find that.



using Microsoft.VisualBasic;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
using System.Speech.Recognition


using System.ComponentModel;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Threading;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }


        private void Form1_Load(object sender, EventArgs e)
        {
            // Create a new SpeechRecognizer instance.
            sr = new SpeechRecognizer()



            // Create a simple grammar that recognizes "red", "green", or "blue".
            Choices colors = new Choices();
            colors.Add("red");
            colors.Add("green");
            colors.Add("blue");
            colors.Add("white");




            GrammarBuilder gb = new GrammarBuilder();
            gb.Append(colors);




            // Create the actual Grammar instance, and then load it into the speech recognizer.
            Grammar g = new Grammar(gb);
            sr.LoadGrammar(g);




            // Register a handler for the SpeechRecognized event.
            sr.SpeechRecognized += new EventHandler<SpeechRecognizedEventArgs>(sr_SpeechRecognized);
        }




        // Simple handler for the SpeechRecognized event.
        private void sr_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
        {
            if(e.Result.Text=="Red");
            MessageBox.Show(e.Result.Text);
        }




        private SpeechRecognizer sr;
 

Answers (1)