Question Making a program that converts speech to text

qsmrf

New member
Joined
Dec 5, 2015
Messages
1
Programming Experience
Beginner
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

C#:
C#:
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;
        }
    }
}

 
Back
Top Bottom