C# rozpoznawanie mowy

0

Chcę napisać program, który będzie rozpoznawał konkretne słowa.
Kod: (tutorial na youtube)

 using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows.Forms;
    using System.Speech.Synthesis;
    using System.Speech.Recognition;
    using System.Threading;
    
    namespace Speaker
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }
            SpeechSynthesizer sSynth = new SpeechSynthesizer();
            PromptBuilder pBuilder = new PromptBuilder();
            SpeechRecognitionEngine sRecognize = new SpeechRecognitionEngine();
            private void Form1_Load(object sender, EventArgs e)
            {
    
            }
    
            private void button1_Click(object sender, EventArgs e)
            {
                pBuilder.ClearContent();
                pBuilder.AppendText(textBox1.Text);
                sSynth.Speak(pBuilder);
            }
    
            private void button2_Click(object sender, EventArgs e)
            {
                button2.Enabled = false;
                button3.Enabled = true;
                Choices sList = new Choices();
                sList.Add(new string[] { "hello", "test", "it works", "how", "are", "you", "today", "i", "am", "fine", "exit", "close", "quit", "so" });
                Grammar gr = new Grammar(new GrammarBuilder(sList));
                try
                {
                    sRecognize.RequestRecognizerUpdate();
                    sRecognize.LoadGrammar(gr);
                    sRecognize.SpeechRecognized += sRecognize_SpeechRecognized;
                    sRecognize.SetInputToDefaultAudioDevice();
                    sRecognize.RecognizeAsync(RecognizeMode.Multiple);
                    sRecognize.Recognize();
                }
    
                catch
                {
                    return;
                }
            }
    
            private void sRecognize_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
            {
                if (e.Result.Text == "exit")
                {
                    Application.Exit();
                }
                else
                {
                    textBox1.Text = textBox1.Text + " " + e.Result.Text.ToString();
                }
    
            }
    
            private void button3_Click(object sender, EventArgs e)
            {
                sRecognize.RecognizeAsyncStop();
                button2.Enabled = true;
                button3.Enabled = false;
            }
        }
    }

Po naciśnięciu przycisku Start Debugger zwraca:

'Speaker.vshost.exe' (CLR v4.0.30319: Speaker.vshost.exe): Loaded 'C:\Users\Łukasz\Documents\Visual Studio 2013\Projects\Speaker\Speaker\bin\Debug\Speaker.exe'. Symbols loaded.
    'Speaker.vshost.exe' (CLR v4.0.30319: Speaker.vshost.exe): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Configuration\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Configuration.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
    Speaker.vshost.exe Information: 0 : SAPI does not implement phonetic alphabet selection.
    'Speaker.vshost.exe' (CLR v4.0.30319: Speaker.vshost.exe): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Speech.resources\v4.0_4.0.0.0_pl_31bf3856ad364e35\System.Speech.resources.dll'. Module was built without symbols.
    A first chance exception of type 'System.InvalidOperationException' occurred in System.Speech.dll

Inne przykłady znalezione w sieci nie działają również. Mój system ma domyślny język polski. Jak to naprawić? Mogę ewentualnie użyć API Google do rozpoznawania mowy?

0

przerzuć ten kod

   SpeechSynthesizer sSynth = new SpeechSynthesizer();
            PromptBuilder pBuilder = new PromptBuilder();
            SpeechRecognitionEngine sRecognize = new SpeechRecognitionEngine();

do konstruktora, otocz przez try, catch, złap wyjątek i pokaż jego message

0

W funkcji button2_Click zmieniłem:

  try
            {
                SpeechSynthesizer sSynth = new SpeechSynthesizer();
                PromptBuilder pBuilder = new PromptBuilder();
                SpeechRecognitionEngine sRecognize = new SpeechRecognitionEngine();
                sRecognize.RequestRecognizerUpdate();
                sRecognize.LoadGrammar(gr);
                sRecognize.SpeechRecognized += sRecognize_SpeechRecognized;
                sRecognize.SetInputToDefaultAudioDevice();
                sRecognize.RecognizeAsync(RecognizeMode.Multiple);
                sRecognize.Recognize();
            }

            catch
            {
                return;
            }

I dostaje

'Speaker.vshost.exe' (CLR v4.0.30319: Speaker.vshost.exe): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Configuration\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Configuration.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
Speaker.vshost.exe Information: 0 : SAPI does not implement phonetic alphabet selection.
'Speaker.vshost.exe' (CLR v4.0.30319: Speaker.vshost.exe): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Speech.resources\v4.0_4.0.0.0_pl_31bf3856ad364e35\System.Speech.resources.dll'. Module was built without symbols.
A first chance exception of type 'System.InvalidOperationException' occurred in System.Speech.dll
The thread 0x189c has exited with code 259 (0x103).
The thread 0x1ad8 has exited with code 259 (0x103).
The program '[5384] Speaker.vshost.exe' has exited with code 0 (0x0).
0

no ale miałeś nam pokazać ten wyjątek

catch (Exception ex)
{
  Console.WriteLine(ex.ToString());
}
0

Vzy po uruchomienie program wchodzi do: sRecognize_SpeechRecognized ?

0

Przecież napisał, że w chwili debugowania programu występuje błąd.

0 użytkowników online, w tym zalogowanych: 0, gości: 0