在C#中使用语音识别的计算器 [英] Calculator using Speech Recognition in C#

查看:122
本文介绍了在C#中使用语音识别的计算器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用语音识别来计算,因此可以通过语音进行管理。例如,用户说多少是56次90?,应用程序应该回答5040。我看了一眼: https://msdn.microsoft.com/en-us/library/office/hh538500(v = office.14).aspx [ ^ ]



这是有用的东西,但我不知道如何将它集成到我的应用程序(Windows窗体)。我使用了Speech命名空间,但在这种情况下,我对如何使用msdn文章中创建的语法感到困惑。



先谢谢! - CCB

I'm trying to do a calculator using speech recognition, so it can be managed through voice. So for example, the user says "How much is 56 times 90?", the application should answer "5040". I gave a look to this: https://msdn.microsoft.com/en-us/library/office/hh538500(v=office.14).aspx[^]

It was something useful, but I did not know how to integrate it to my app (windows form). I have used the Speech namespace, but in this case, I get confused about how to use the grammar created in the msdn article.

Thanks in Advance! - CCB

推荐答案

这是如何:

https://msdn.microsoft.com/en-us/library/system.speech.recognition%28v=vs.110%29.aspx [ ^ ]:

https://msdn.microsoft.com/en-us/library/system.speech.recognition.speechrecognizer(v = vs.110).aspx [ ^ ],

https://msdn.microsoft.com/en-us/library/system.speech.recognition.speechrecognitionengin e(v = vs.110).aspx [ ^ ]。



小心这两个识别器:一个只能用于STA线程和另一个仅在MTA线程中。不幸的是,MSDN文档对此保持沉默。这不是如果这与您正在使用的UI库的兼容公寓状态相矛盾,您可以始终使用单独的线程并在启动之前设置其公寓状态:

https://msdn.microsoft.com/en-us/library/system .threading.thread.setapartmentstate%28v = vs.110%29.aspx [ ^ ]。



另一条建议:认可忠诚远非完美。太复杂的语法很容易混淆你的识别器。因此,更好地通过数字,算术运算符的名称和有限数量的命令来限制功能。我期望的最复杂的问题是对大数字的认可。你无法在语法中融入太多的东西。所以,你可能想要开始逐位输入数字。



-SA
This is how:
https://msdn.microsoft.com/en-us/library/system.speech.recognition%28v=vs.110%29.aspx[^]:
https://msdn.microsoft.com/en-us/library/system.speech.recognition.speechrecognizer(v=vs.110).aspx[^],
or https://msdn.microsoft.com/en-us/library/system.speech.recognition.speechrecognitionengine(v=vs.110).aspx[^].

Be careful with these two recognizers: one can work only in STA thread and another one only in MTA thread. Unfortunately, MSDN documentation keeps silence about it. This is not If this contradicts to the compatible Apartment States of the UI library you are using, you can always use a separate thread and set its Apartment State before starting it:
https://msdn.microsoft.com/en-us/library/system.threading.thread.setapartmentstate%28v=vs.110%29.aspx[^].

Another advice: the recognition fidelity is quite far from perfect. Too complex grammar can easily confuse your recognizer. So, better limit the functionality by figures, names of arithmetic operators and limited number of commands. Most complex problem I expect would be recognition of big numbers. You cannot fit too many of them in grammar. So, you may want to start with entering numbers digit by digit.

—SA


这篇关于在C#中使用语音识别的计算器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆