slowhand
slowhand

Reputation: 11

C# Speech Recognition Library not able to recognize dictation of "nonsense words"

I am using "System.Speech.Recognition" and "System.Speech.Synthesis" libraries from C# to create a small speech synthesis windows application.

The app works fine with words fed in its grammar and recognizes but fails to recognize other words. ( like "zapssss Hello zapssss" , which is not actually a proper phrase). Help on this section required. I am a complete newbie to C#.

The code portion is as follows:-

   public string[] get_data_list() 
    {
        int counter = 0;
        string line;
        string[] data_list = new string[8];
        System.IO.StreamReader file = new System.IO.StreamReader(@"C:\\Users\\usr\\Desktop\\Voice Recognition\\Voice Recognition\\data_dict.txt");
        while ((line = file.ReadLine()) != null)
        {
            data_list[counter] = line;
            System.Console.WriteLine(data_list[counter]);
            counter++;
        }

        file.Close();
        Console.WriteLine("Hello");
        Console.WriteLine(data_list);
        return data_list;
    }

    private void Form1_Load(object sender, EventArgs e)
    {
        Choices commands = new Choices();

        string[] voice_dict = get_data_list();

        foreach (string arrItem in voice_dict)
        {
            Console.WriteLine(arrItem);
        }

        commands.Add(voice_dict);
        GrammarBuilder gBuilder = new GrammarBuilder();
        gBuilder.Append(commands);
        Grammar grammar = new Grammar(gBuilder);
        recEngine.LoadGrammarAsync(grammar);
        recEngine.SetInputToDefaultAudioDevice();
        recEngine.SpeechRecognized += recEngine_SpeechRecognized;
    }

    void recEngine_SpeechRecognized(object sender, SpeechRecognizedEventArgs e) 
    {
        System.Console.WriteLine("Entered Event");
        string[] voice_dict = get_data_list();
        string msg;
        string user_recorded_voice = e.Result.Text;
        string voice_check_flag = check_voice_available(user_recorded_voice, voice_dict);

        switch (voice_check_flag)
        {

            case "not found":
                System.Console.WriteLine("Match Not Found for " + user_recorded_voice);
                msg = ("\nText " + user_recorded_voice + " Not Recognized");
                text_box.Text += msg;
                synth.SpeakAsync(msg);
                break;
            default:
                Console.WriteLine("\nMessage recieved " + voice_check_flag);
                text_box.Text += voice_check_flag;
                synth.SpeakAsync(voice_check_flag);
                break;
        }

    }

Upvotes: 0

Views: 610

Answers (1)

Mihir Dave
Mihir Dave

Reputation: 4014

According to Microsoft you'll only be able to detect the text from speech which you trained your system for (Using Grammar) Reference

Though it has different event That you can look into

SpeechRecognitionRejected

SpeechDetected

But as of now you can't know what user has spoken outside of your trained grammar set.

Upvotes: 1

Related Questions