Jump to content

Check out our Community Blogs

Register and join over 40,000 other developers!

Recent Status Updates

View All Updates

- - - - -

Making a program that converts speech to text

c# console application

This topic has been archived. This means that you cannot reply to this topic.
No replies to this topic

#1 MohammadQasim


    CC Lurker

  • Just Joined
  • Pip
  • 1 posts

Posted 04 December 2015 - 10:17 PM

so I got the code from the msdn website:
https://msdn.microso...udiostream.aspx , just to check and see if everything is working. 
and since i do not have the wav file specified in the original code i downloaded my own wav file and inserted the address of it.
the program works but it prints out something completely different words that are not even in the wav file audio.

here is the code

using System;
using System.Globalization;
using System.IO;
using System.Speech;
using System.Speech.AudioFormat;
using System.Speech.Recognition;
using System.Threading;

namespace InputExamples
    class Program
        // Indicate whether asynchronous recognition is complete.
        static bool completed;

        static void Main(string[] args)
            using (SpeechRecognitionEngine recognizer =
              new SpeechRecognitionEngine(new CultureInfo("en-US")))

                // Create and load a grammar.
                Grammar dictation = new DictationGrammar();
                dictation.Name = "Dictation Grammar";


               //Configure the input to the recognizer.


                  //new SpeechAudioFormatInfo(
                    //44100, AudioBitsPerSample.Sixteen, AudioChannel.Mono));

                // Attach event handlers.
                recognizer.SpeechRecognized +=
                  new EventHandler<SpeechRecognizedEventArgs>(
                recognizer.RecognizeCompleted +=
                  new EventHandler<RecognizeCompletedEventArgs>(

                // Perform recognition of the whole file.
                Console.WriteLine("Starting asynchronous recognition...");
                completed = false;

                while (!completed)

            Console.WriteLine("Press any key to exit...");

        // Handle the SpeechRecognized event.
        static void SpeechRecognizedHandler(
          object sender, SpeechRecognizedEventArgs e)
            if (e.Result != null && e.Result.Text != null)
                Console.WriteLine("  Recognized text =  {0}", e.Result.Text);
                Console.WriteLine("  Recognized text not available.");

        // Handle the RecognizeCompleted event.
        static void RecognizeCompletedHandler(
          object sender, RecognizeCompletedEventArgs e)
            if (e.Error != null)
                Console.WriteLine("  Error encountered, {0}: {1}",
                  e.Error.GetType().Name, e.Error.Message);
            if (e.Cancelled)
                Console.WriteLine("  Operation cancelled.");
            if (e.InputStreamEnded)
                Console.WriteLine("  End of stream encountered.");

            completed = true;

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download