我正在使用SpeechRecognizer,看看它是否支持我正在设计的应用程序的特性。
下面的代码适用于单个单词。但是,分析一个短语有可能吗?我的应用程序不需要使用大的短语,只有3个或4个单词的短语。举个例子,我试图让这个应用程序看到有多个“单词”在被表达(尽管技术上它不是多个单词)。
static void Main(string[] args)
{
// Create an in-process speech recognizer for the en-US locale.
using ( SpeechRecognitionEngine recognizer = new SpeechRecognitionEngine( new System.Globalization.CultureInfo("en-US")))
{
Choices c = new Choices();
c.Add("one");
c.Add("two");
c.Add("three");
c.Add("twenty");
var gb = new GrammarBuilder(c);
var g = new Grammar(gb);
recognizer.LoadGrammar(g);
// Add a handler for the speech recognized event.
recognizer.SpeechRecognized += new EventHandler<SpeechRecognizedEventArgs>(recognizer_SpeechRecognized);
// Configure input to the speech recognizer.
recognizer.SetInputToDefaultAudioDevice();
// Start asynchronous, continuous speech recognition.
recognizer.RecognizeAsync(RecognizeMode.Multiple);
// Keep the console window open.
while (true)
{
Console.ReadLine();
}
}
}
// Handle the SpeechRecognized event.
static void recognizer_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
{
Console.WriteLine("Recognized text: " + e.Result.Text);
}
我会说话,它会返回一,二,三和二十。但如果我说是二十一号,那就只有二十个了。
有没有一种方法来扩展多少个“音节”(我甚至不确定这里使用的术语),它将分析?
发布于 2022-07-30 07:00:59
答案是“是”/“否”,似乎没有办法使“21”合乎逻辑,所以我认为这将是一个限制,除非我另有指出。然而,在阅读MS文档的更多内容时,我发现如下:
static Grammar CreateServicesGrammar(string grammarName)
{
// Create a grammar for finding services in different cities.
Choices services = new Choices(new string[] { "restaurants", "hotels", "gas stations" });
Choices cities = new Choices(new string[] { "Seattle", "Boston", "Dallas" });
GrammarBuilder findServices = new GrammarBuilder("Find");
findServices.Append(services);
findServices.Append("near");
findServices.Append(cities);
// Create a Grammar object from the GrammarBuilder.
Grammar servicesGrammar = new Grammar(findServices);
servicesGrammar.Name = ("FindServices");
return servicesGrammar;
}
它允许创造短语,而且似乎运作得很好。
https://stackoverflow.com/questions/73171586
复制