CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Dec 2015
    Posts
    2

    Making a program that converts speech to text

    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.

    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";
    
                    recognizer.LoadGrammar(dictation);
    
                   //Configure the input to the recognizer.
    
                    recognizer.SetInputToWaveStream(
                File.OpenRead(@"C:\Users\Qasim\Desktop\wav3.wav"));
    
    
                   //recognizer.SetInputToAudioStream(
                      //File.OpenRead(@"C:\Users\Qasim\Desktop\wav3.wav"),
                      //new SpeechAudioFormatInfo(
                        //44100, AudioBitsPerSample.Sixteen, AudioChannel.Mono));
    
                    // Attach event handlers.
                    recognizer.SpeechRecognized +=
                      new EventHandler<SpeechRecognizedEventArgs>(
                        SpeechRecognizedHandler);
                    recognizer.RecognizeCompleted +=
                      new EventHandler<RecognizeCompletedEventArgs>(
                        RecognizeCompletedHandler);
    
                    // Perform recognition of the whole file.
                    Console.WriteLine("Starting asynchronous recognition...");
                    completed = false;
                    recognizer.RecognizeAsync(RecognizeMode.Multiple);
    
                    while (!completed)
                    {
                        Thread.Sleep(333);
                    }
                    Console.WriteLine("Done.");
                }
    
                Console.WriteLine();
                Console.WriteLine("Press any key to exit...");
                Console.ReadKey();
            }
    
            // 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);
                }
                else
                {
                    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;
            }
        }
    }

  2. #2
    Join Date
    Mar 2001
    Posts
    2,529

    Re: Making a program that converts speech to text

    I don't see a question here. Speech recognition software has gotten a lot better in the last decade.
    I have found that in cases where speech software sucks though, if you try to sound like a robot, the
    software tends to pick up your speech better. (and not a robot that is trying to sound more like a human either. Like the computer Joshua from the movie War Games)
    ahoodin
    To keep the plot moving, that's why.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured