2

ユーザーからの複数の単語を認識するアプリケーションを構築しています。したがって、認識された単語を使用して文をまとめます。

これが私が今持っているものです:

namespace SentenceRecognitionFramework__v1_
{
    public partial class Form1 : Form
    {

        SpeechRecognitionEngine recog = new SpeechRecognitionEngine();
        SpeechSynthesizer sp = new SpeechSynthesizer();

        public Form1()
        {
            InitializeComponent();
        }

        private void btnListen_Click(object sender, EventArgs e)
        {
            Choices sList = new Choices();
            sList.Add(new String[] { "what","is", "a", "car" });

            Grammar gr = new Grammar(new GrammarBuilder(sList));

            recog.RequestRecognizerUpdate();
            recog.LoadGrammar(gr);
            recog.SpeechRecognized += sRecognize_SpeechRecognized;
            recog.SetInputToDefaultAudioDevice();
            recog.RecognizeAsync(RecognizeMode.Multiple);
            recog.SpeechRecognitionRejected += sRecognize_SpeechRecognitionRejected;
        }

        private void sRecognize_SpeechRecognitionRejected(object sender, SpeechRecognitionRejectedEventArgs e)
        {
            sentenceBox.Text = "Sorry, I couldn't recognize";
        }

        private void sRecognize_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
        {
            sentenceBox.Text = e.Result.Text.ToString();
        }
    }
}

ただし、このコードは一度に 1 つの単語しか認識しません。これを行うためにコードを編集しても:

private void sRecognize_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
        {
            sentenceBox.Text = sentenceBox.Text + " " + e.Result.Text.ToString();
        }

「車って何?」という言葉を途切れることなく連続して発声すると、アプリが連続して単語を認識できなくなります。

プログラムが、定義された単語を使用して作成された文全体を認識し、文を発声するときにスピーチを中断することなく、プログラムが認識できるようにするには、どのような変更を加えることができますか?

必要な出力:

私は次の言葉を発します:車とは

アプリケーション表示:車とは

完璧な例: Google 音声認識Google は、単語ライブラリにある単語を使用して文を作成します。

よろしくお願いします:)

4

2 に答える 2

3

この回答は少し遅れているかもしれませんが、この問題に対する実際の回答がある場所は他にありません。他の人の時間とフラストレーションを軽減するために、私が行った方法を次に示します。

using System;
using System.Threading;
using System.Speech;
using System.Speech.Synthesis;
using System.Speech.Recognition;

namespace SpeachTest
{
public class GrammerTest
{
        static void Main()
        {
        Choices choiceList = new Choices();
        choiceList.Add(new string[]{"what", "is", "a", "car", "are", "you", "robot"} );

        GrammarBuilder builder = new GrammarBuilder();
        builder.Append(choiceList);
        Grammar grammar = new Grammar(new GrammarBuilder(builder, 0, 4) );   //Will recognize a minimum of 0 choices, and a maximum of 4 choices

            SpeechRecognizer speechReco = new SpeechRecognizer();
            speechReco.LoadGrammar(grammar);



        }
}
}

ここでの鍵はこの行です

new GrammarBuilder(ビルダー, 0, 4)

builderこれは、要素 form の最大 4 回の繰り返しと最小ゼロを認識するように音声認識エンジンに指示します。

だからそれは今認識します

"what is a car"

4回以上繰り返したい場合は、変更するだけですnew GrammarBuilder(builder, 0, 4)

new GrammarBuilder(builder, 0 "the number of repetitions you want")

詳細については、これを参照してください GrammarBuilder(builder, minRepeat, maxRepeat)

于 2015-02-11T23:07:26.087 に答える