gpt4 book ai didi

c# - 语法语言与语音识别器的语言不匹配

转载 作者:行者123 更新时间:2023-11-30 14:10:20 25 4
gpt4 key购买 nike

美好的一天!这是关于Microsoft Server Speech SDK v11.0(服务器版)。

我在 MSDN sample 运行了测试示例.所以英语短语 -red,blue - 识别得很好。但我也想识别俄语 - 安装 Microsoft Speech Recognition Language -TELE (ru-RU) 并运行我的应用程序/

代码:

 static void DoWork()
{

Thread.CurrentThread.CurrentCulture = new CultureInfo("ru-RU");
Thread.CurrentThread.CurrentUICulture = new CultureInfo("ru-RU");

// Create a new SpeechRecognitionEngine instance.
SpeechRecognitionEngine sre = new SpeechRecognitionEngine();

// Configure the input to the recognizer.
sre.SetInputToWaveFile(@"c:\Test\красный.wav");

// Create a simple grammar that recognizes "red", "green", or "blue".
Choices colors = new Choices();
// colors.Add(new string[] { "red", "green", "blue","красный" });
colors.Add(new string[] { "красный" }); //russian word- "red"

// Create a GrammarBuilder object and append the Choices object.
GrammarBuilder gb = new GrammarBuilder();
gb.Culture = new CultureInfo("ru-RU"); // add Culture Info

gb.Append(colors);

Console.WriteLine(gb.Culture.CultureTypes);

// Create the Grammar instance and load it into the speech recognition engine.
Grammar g = new Grammar(gb);
sre.LoadGrammar(g);

// Register a handler for the SpeechRecognized event.
sre.SpeechRecognized +=
new EventHandler<SpeechRecognizedEventArgs>(sre_SpeechRecognized);

// Start recognition.
sre.Recognize();
}

// Create a simple handler for the SpeechRecognized event.
static void sre_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
{
Console.WriteLine(String.Format("Speech recognized: {0}",e.Result.Text));

}

错误出现在这一行:

 sre.LoadGrammar(g);

The language for the grammar does not match the language of the speech recognizer.

那么,如何解决这个错误呢?我尝试设置 CultureInfo,但它不起作用...谢谢!

最佳答案

更改 GrammarBuilder.Culture 属性将解决此错误。

之后:

GrammarBuilder gb = new GrammarBuilder();

添加:

gb.Culture = Thread.CurrentThread.CurrentCulture

使语法文化与识别器匹配。

关于c# - 语法语言与语音识别器的语言不匹配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24630507/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com