首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >阅读SpeechRecognitionEngine中的一个短语

阅读SpeechRecognitionEngine中的一个短语
EN

Stack Overflow用户
提问于 2022-07-29 22:37:08
回答 1查看 25关注 0票数 0

我正在使用SpeechRecognizer,看看它是否支持我正在设计的应用程序的特性。

下面的代码适用于单个单词。但是,分析一个短语有可能吗?我的应用程序不需要使用大的短语,只有3个或4个单词的短语。举个例子,我试图让这个应用程序看到有多个“单词”在被表达(尽管技术上它不是多个单词)。

代码语言:javascript
运行
复制
    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);
    }

我会说话,它会返回一,二,三和二十。但如果我说是二十一号,那就只有二十个了。

有没有一种方法来扩展多少个“音节”(我甚至不确定这里使用的术语),它将分析?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-07-30 15:00:59

答案是“是”/“否”,似乎没有办法使“21”合乎逻辑,所以我认为这将是一个限制,除非我另有指出。然而,在阅读MS文档的更多内容时,我发现如下:

代码语言:javascript
运行
复制
    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;
    }

它允许创造短语,而且似乎运作得很好。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/73171586

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档