且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在C#中使用语音识别的计算器

更新时间:2022-06-25 20:39:30

这是如何:

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