none
Activating windows speech recognition RRS feed

  • Question

  • Hi. I'm looking for a way to activate the speech recognition for windows 10, more specifically text to speech. Is there a way to activate it or other windows properties with code?
    Thursday, July 19, 2018 11:14 PM

All replies

  • Hi Antti Veikkolainen,

    Thank you for posting here.

    For your question, I am not sure what windows speech recognition you want to activate. If you want to make text to speech, you could try the code below.

    In designer.

    Here is the code.

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Speech.Synthesis;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows.Forms;
    using System.Globalization;
    using System.Threading;
    using System.Speech.Recognition;
    
    namespace text_to_speech
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }
            SpeechSynthesizer speechSynthesizerObj;
            private void button1_Click(object sender, EventArgs e)
            {
                if (textBox1.Text != "")
                {
                    speechSynthesizerObj = new SpeechSynthesizer();
                    //Asynchronously speaks the contents present in RichTextBox1    
                    speechSynthesizerObj.SpeakAsync(textBox1.Text);
                    button2.Enabled = true;
                    button3.Enabled = true;
    
                }
    
            }
    
            private void button2_Click(object sender, EventArgs e)
            {
                if (speechSynthesizerObj != null)
                {
                    //Gets the current speaking state of the SpeechSynthesizer object.    
                    if (speechSynthesizerObj.State == SynthesizerState.Speaking)
                    {
                        //Pauses the SpeechSynthesizer object.    
                        speechSynthesizerObj.Pause();
                        button3.Enabled = true;
                        button1.Enabled = false;
                    }
    
    
                }
            }
    
            private void button3_Click(object sender, EventArgs e)
            {
                if (speechSynthesizerObj != null)
                {
                    if (speechSynthesizerObj.State == SynthesizerState.Paused)
                    {
                        //Resumes the SpeechSynthesizer object after it has been paused.    
                        speechSynthesizerObj.Resume();
                        button3.Enabled = false;
                        button1.Enabled = true;
                    }
                }
    
            }
    
            private void button4_Click(object sender, EventArgs e)
            {
                if (speechSynthesizerObj != null)
                {
                    //Disposes the SpeechSynthesizer object    
                    speechSynthesizerObj.Dispose();
                    button1.Enabled = true;
                    button2.Enabled = false;
                    button3.Enabled = false;
                    button4.Enabled = false;
                }
    
            }
        }
    }

    Best Regards,

    Wendy


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, July 20, 2018 1:50 AM
    Moderator