簡體   English   中英

如何在C#中將語法(規則)和聽寫(言論自由)與SpeechRecognizer混合

[英]How to mix Grammar (Rules) & Dictation (Free speech) with SpeechRecognizer in C#

我非常喜歡Microsofts最新的語音識別(和SpeechSynthesis)產品。

http://msdn.microsoft.com/en-us/library/ms554855.aspx

http://estellasays.blogspot.com/2009/04/speech-recognition-in-cnet.html

但是我覺得在使用語法時我有點受限。

不要誤解我的語法,語法識別確切地指出了要注意的單詞/短語,但是如果我想要它能夠識別出一些我沒有注意到的東西呢? 或者我想解析一個半預定命令名和半隨機字的短語?

例如..

情景A - 我說“谷歌[漏油事件]”,我希望它用括號中的搜索結果打開谷歌,這可能是任何東西。

場景B - 我說“找到[曼徹斯特]”,我想讓它在谷歌地圖或任何其他未預先確定的地方搜索曼徹斯特

我希望它知道'谷歌'和'定位'是命令,它是參數之后的東西(可能是任何東西)。

問題:有沒有人知道如何混合使用預先確定的語法(語音識別應該識別的單詞)和不在預定語法中的單詞?

代碼片段..

using System.Speech.Recognition;

...
...

SpeechRecognizer rec = new SpeechRecognizer();
rec.SpeechRecognized += rec_SpeechRecognized;

var c = new Choices();
c.Add("search");

var gb = new GrammarBuilder(c);
var g = new Grammar(gb);
rec.LoadGrammar(g);
rec.Enabled = true; 

...
...

void rec_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
{
    if (e.Result.Text == "search")
    {
        string query = "How can I get a word not defined in Grammar recognised and passed into here!";

        launchGoogle(query);
    }
}

...
...


private void launchGoogle(string term)
{
    Process.Start("IEXPLORE", "google.com?q=" + term);
}

您可以嘗試這樣的事情......它指定了已知命令的列表..但是也可以讓您在之后使用開放式聽寫。 它希望在開放式聽寫之前有一個命令..但是你可以反轉這個...並追加th然而,通過在命令類型(“”)中添加一個空格,它也會讓你直接聽寫部分。

Choices commandtype = new Choices();
commandtype.Add("search");
commandtype.Add("print");
commandtype.Add("open");
commandtype.Add("locate");

SemanticResultKey srkComtype = new SemanticResultKey("comtype",commandtype.ToGrammarBuilder());

 GrammarBuilder gb = new GrammarBuilder();
 gb.Culture = System.Globalization.CultureInfo.CreateSpecificCulture("en-GB");
 gb.Append(srkComtype);
 gb.AppendDictation();

 Grammar gr = new Grammar(gb);

然后在你的識別器上只使用結果文本等

private void recognizer_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
{
    System.Console.WriteLine(e.Result.Text);

}

您可以向結構中添加更多選項和SemanticResultKeys,以便根據需要制作更復雜的模式。 也是一個通配符(例如gb.AppendWildcard();)。

你有兩個選擇:

  1. 您可以使用GrammarBuilder :: AppendDictation將自由文本的聽寫節點用於自由文本。 問題在於,由於識別器沒有任何上下文,因此識別不是最高質量的。
  2. 您可以使用textbuffer節點並使用GrammarBuilder :: Append(String,SubsetMatchingMode)提供一組項目。 這將為識別器提供足夠的上下文,以獲得高質量的識別,而無需每次都重建整個語法樹。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM