Click here to Skip to main content
15,437,139 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I am making a speech to text application in console app I have convert my console app to window form but it was working fine but when I speak anything the word is not recognized through button

What I have tried:

using Microsoft.CognitiveServices.Speech;
using Microsoft.CognitiveServices.Speech.Audio;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApp5
    public partial class Form1 : Form
        private const string cKey = "key";

        private const string cRegion = "region";

        public static async Task SpeechToTextAsync()


            var config = SpeechConfig.FromSubscription(cKey, cRegion);

            using (SpeechRecognizer recognizer = new SpeechRecognizer(config))
                await Recognize(recognizer);



        private static async Task Recognize(SpeechRecognizer recognizer)


            var result = await recognizer.RecognizeOnceAsync();

            if (result.Reason == ResultReason.RecognizedSpeech)

                //Console.WriteLine($"Recognized: {result.Text}");


            //else if (result.Reason == ResultReason.NoMatch)
             //Console.WriteLine("Speech could not be recognized.");

            else if (result.Reason == ResultReason.Canceled)


                var cancellation =



                    ($"Cancelled due to reason={cancellation.Reason}");

                if (cancellation.Reason == CancellationReason.Error)



                        ($"Error code={cancellation.ErrorCode}");


                        ($"Error details={cancellation.ErrorDetails}");


                        ($"Did you update the subscription info?");




        public Form1()

        private void Form1_Load(object sender, EventArgs e)


        private void button1_Click(object sender, EventArgs e)
            //Console.WriteLine("Please press enter to exit.");
Updated 2-Aug-22 6:53am
Afzaal Ahmad Zeeshan 2-Aug-22 8:48am    
The best you can do is debug, and see if the call is being made. The SDK can help you with more, like if there are any networking issues, or the API key is not working.

1 solution

Your code does not compare with actual working code; console or otherwise. e.g. where is your "LoadGrammer" or event handler hookup?

SpeechRecognitionEngine Class (System.Speech.Recognition) | Microsoft Docs[^]
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900