none
System.Speech.Recognition with "Date" and "Time" RRS feed

  • Question

  • Hi everyone.

    I am working with a speech recognition project and every time I ask "Whats the date" I get the time instead of the date.

    I made this sample application to showcase the problem.

    The output is always "time". Does anyone know how I get the recognizer to return date when I ask for the date and the time when I ask for the time.

    The project is a console app targeting .Net Framework 4.5.2.

    thanks

    using System;
    using System.Speech.Recognition;
    
    namespace RecognitionTest
    {
        class Program
        {
            static void Main(string[] args)
            {
                SpeechRecognitionEngine recognizer = new SpeechRecognitionEngine();
    
                Choices colors = new Choices();
                colors.Add(new string[] { "time", "date" });
    
                GrammarBuilder gb = new GrammarBuilder();
                gb.Append(colors);
    
                Grammar g = new Grammar(gb);
                recognizer.LoadGrammar(g);
    
                recognizer.SpeechRecognized +=  new EventHandler<SpeechRecognizedEventArgs>(sre_SpeechRecognized);
                recognizer.SetInputToDefaultAudioDevice();
                recognizer.RecognizeAsync(RecognizeMode.Multiple);
    
                Console.ReadLine();
            }
    
            static void sre_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
            {
                Console.WriteLine(e.Result.Text);
            }
        }
    }
    

    Sunday, December 4, 2016 5:14 AM

Answers

  • I tried on a computer with a soundblaster sound card and it could understands them fine. So the problem was the hardware.

    • Marked as answer by hypodyne1 Friday, December 9, 2016 10:24 PM
    • Edited by hypodyne1 Friday, December 9, 2016 11:21 PM
    Friday, December 9, 2016 10:23 PM

All replies

  • Hi hypodyne1,

    >>The output is always "time". Does anyone know how I get the recognizer to return date when I ask for the date and the time when I ask for the time.

    Time is expected.

    Choices colors = new Choices();
                colors.Add(new string[] { "time", "date" });

    The method builds a grammar incrementally using a Choices instance to add the strings "time", "date".It then creates a GrammarBuilder instance using the Choices object. The method then initializes a Grammar instance with the GrammarBuilder object created earlier. The grammar, which is capable of recognizing the words "time", "date", , is then loaded into the speech recognizer. Finally, the Main method registers an event handler for the SpeechRecognized event.

    Here the picture shows

    For more details, please refer to Get Started with Speech Recognition

    Best regards,

    Kristin


    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.

    Monday, December 5, 2016 2:46 AM
  • Let me show you another example.

    sing System;
    using System.IO;
    using System.Speech.Recognition;
    
    namespace RecognitionTest
    {
        class Program
        {
            static void Main(string[] args)
            {
                SpeechRecognitionEngine recognizer = new SpeechRecognitionEngine();
    
                Choices colors = new Choices();
                colors.Add(new string[] { "red", "green", "blue", "date", "time" });
    
                GrammarBuilder gb = new GrammarBuilder();
                gb.Append(colors);
       
                Grammar g = new Grammar(gb);
                recognizer.LoadGrammar(g);
    
                recognizer.SpeechRecognized += new EventHandler<SpeechRecognizedEventArgs>(sre_SpeechRecognized);
                recognizer.SetInputToDefaultAudioDevice();
                recognizer.RecognizeAsync(RecognizeMode.Multiple);
    
                Console.ReadLine();
            }
    
            static void sre_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
            {
                Console.WriteLine(e.Result.Text);
            }
        }
    }
    

    I run the program and speak each of the colors in order in a very clear voice and I get this.

    red
    green
    blue
    time
    time


    Monday, December 5, 2016 9:25 AM
  • Is it able to recognise “date” if you remove “time” in the last example?


    • Edited by Viorel_MVP Monday, December 5, 2016 11:35 AM
    Monday, December 5, 2016 11:34 AM
  • Yes it does recognize date if I remove time.

    • Edited by hypodyne1 Tuesday, December 6, 2016 9:31 AM
    Tuesday, December 6, 2016 9:28 AM
  • Maybe create a separate grammar for “date”, and load it with another LoadGrammar function. Perform some experiments with different order of data and with Priority and Weight values of Grammar.

    See also: https://blogs.msdn.microsoft.com/rlucero/2012/02/03/speech-recognition-using-multiple-grammars-to-improve-recognition/

    • Proposed as answer by Kristin Xie Friday, December 9, 2016 1:10 AM
    Tuesday, December 6, 2016 10:42 AM
  • I tried on a computer with a soundblaster sound card and it could understands them fine. So the problem was the hardware.

    • Marked as answer by hypodyne1 Friday, December 9, 2016 10:24 PM
    • Edited by hypodyne1 Friday, December 9, 2016 11:21 PM
    Friday, December 9, 2016 10:23 PM
  • I have moved to UWP and the recognition rate is a huge improvement over speech recognizer in WPF.
    Monday, April 10, 2017 9:58 AM