如何在语音到文本应用中实现多线程 [英] how implement multi threading in speech to text application
本文介绍了如何在语音到文本应用中实现多线程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我如何将这个概念语音用于文本应用....
how can i use this concept speech to text application....
推荐答案
看看这些CP文章
C#Speech to Text [ ^ ]
和
另一种调用UI的方法工人线程 [ ^ ]
Have a look at these CP articles
C# Speech to Text[^]
and
Another way to Invoke UI from a Worker Thread[^]
除了解决方案1.
有一个特定的使用适用于任何线程的语音识别时出现问题,即使这是您的应用程序的起始线程:公寓状态。识别器有一个严重的限制:每个人只能在一个线程中工作,并且这个线程应该是某个公寓状态。此外,我没有在文档中找到它,它只能从与此问题相关的例外中找到。
所以,System.Speech。 Recognition.SpeechRecognizer
需要STA线程,System.Speech.Recognition.SpeechRecognitionEngine
MTA。请参阅(此要求未记录:
http://msdn.microsoft.com/en-us/library/system.speech.recognition.speechrecognizer%28v=vs.110%29.aspx 一> [ ^ ],
http://msdn.microsoft.com/en-us/library/system.speech.recognition.speechrecognitionengine%28v=vs.110%29.aspx [ ^ ]。
现在,这是为什么单独的线程可能很重要的几个原因之一(并且,与其他原因不同,这个绝对是c ritical)。例如,WPF应用程序只能使用STAThread
。要使用System.Speech.Recognition.SpeechRecognitionEngine
,您总是需要在不同的线程中使用MTAThread。具体如下:
http://msdn.microsoft.com/en-us/library/system.threading.thread.getapartmentstate%28v=vs.110%29.aspx [ ^ ]。br />
请注意,您无法从同一个线程调用Thread.SetApartmentState
。它可以通过线程用来启动线程,并且仅在启动之前完成。
现在,两个仅限控制台的应用程序都可以在<$ c $中工作c> MTAThread 和STAThread
。System.Windows.Forms
也是如此。如果要在应用程序的各个主线程上执行一个识别器,则需要确保将正确的属性应用于应用程序的入口点方法,例如:
In addition to Solution 1.
There is one specific problem when you use speech recognition which applies to any thread, even if this is the starting thread of your application: apartment states. Recognizers have a serious limitation: each of one can work only in one thread, and this thread should be of one certain apartment state. Also, I did not found this in documentation, it can only be found from exceptions related to this problem.
So,System.Speech.Recognition.SpeechRecognizer
requires STA thread, andSystem.Speech.Recognition.SpeechRecognitionEngine
MTA. Please see (this requirement is not documented:
http://msdn.microsoft.com/en-us/library/system.speech.recognition.speechrecognizer%28v=vs.110%29.aspx[^],
http://msdn.microsoft.com/en-us/library/system.speech.recognition.speechrecognitionengine%28v=vs.110%29.aspx[^].
Now, this is one of the several reasons why a separate thread could be important (and, unlike other reasons, this one is absolutely critical). For example, WPF application can only useSTAThread
. To useSystem.Speech.Recognition.SpeechRecognitionEngine
, you always need to use MTAThread in a different thread. This is how:
http://msdn.microsoft.com/en-us/library/system.threading.thread.getapartmentstate%28v=vs.110%29.aspx[^].
Note that you cannot callThread.SetApartmentState
from the same thread. It can be done by the thread uses to start the thread, and only before starting it.
Now, both console-only applications can work in bothMTAThread
andSTAThread
. Same goes aboutSystem.Windows.Forms
. If you want to execute one the recognizers on respective main threads of the application, you need to make sure you have correct attribute applied to the entry-point method of the application, for example:
using System;
//...
[STAThread]
static void Main(string[] args) { /* ... */ }
或
or
[MTAThread]
static void Main(string[] args) { /* ... */ }
这篇关于如何在语音到文本应用中实现多线程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文