Click here to Skip to main content
15,882,063 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
how can i use this concept speech to text application....
Posted

Have a look at these CP articles

C# Speech to Text[^]
and
Another way to Invoke UI from a Worker Thread[^]
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 26-Feb-14 15:56pm    
I voted 4. It looks like neither you, nor the authors of both articles, did not pay attention to one most critical problem of the two recognizers: requirements for apartment state.
As far as I know, this problem is not properly documented in MSDN, but the exceptions thrown at the attempt to their use clearly show the way to use the recognizers.
Please see my answer.
—SA
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, and System.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 use STAThread. To use System.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 call Thread.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 both MTAThread and STAThread. Same goes about System.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:
C#
using System;

//...

[STAThread]
static void Main(string[] args) { /* ... */ }

or
C#
[MTAThread]
static void Main(string[] args) { /* ... */ }

—SA
 
Share this answer
 
Comments
ch.haya 3-Mar-14 13:51pm    
actually i want to convert audio file in to text line by line which need multi threads to handle this situation ,so kindly guide me in this way ....
Sergey Alexandrovich Kryukov 3-Mar-14 14:21pm    
I've just done it, don't you think so?
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900