threaded TextToSpeech

Forum for discussion on different user applications
Locked
tiziano
Posts: 18
Joined: 19 Oct 2008, 10:22

threaded TextToSpeech

Post by tiziano » 27 Feb 2009, 19:10

Hello,
I need to use TextToSpeech inside the Execute() method of an OSThread, but when I try to do that I always get a runtime error.
If I don't use threads it works fine. I know that TextToSpeech doesn't blocks itself but for how I have designed my application I need this feature.
Any suggestions?
Moreover I get a runtime error also when I try to call the destructor of a TextToSpeech object.

Thanks for your help,

Tiziano

tiziano
Posts: 18
Joined: 19 Oct 2008, 10:22

Post by tiziano » 19 Mar 2009, 04:29

Nobody as suggestion for this problem? I think there could be a bug either in the class TextToSpeech either in OSThread.. that both belong to BCI2000

gschalk
Posts: 615
Joined: 28 Jan 2003, 12:37

Bug?

Post by gschalk » 28 Mar 2009, 11:53

Tiziano,

there is no bug in the TextToSpeech class. The likely reason for this problem is that BCI2000 is not thread-safe in its current implementation.
The TextToSpeech class automatically takes care of performing some initialization/deinitialization when the first instance is created/the last instance is deleted.

As a possible workaround, you might try to create a dummy TextToSpeech object from your main thread that lives as long as you are using TextToSpeech objects. You can do this by adding a line

TextToSpeech dummy;

to your application module's main cpp file, immediately before the CoreModuleVCL().Run() call.

Gerv and Juergen

tiziano
Posts: 18
Joined: 19 Oct 2008, 10:22

still problems

Post by tiziano » 04 Apr 2009, 06:14

Gerv,

I've tried to create a dummy TexToSpeech where you told me, but the situation is not solved. I don't get a runtime error but a message like this:

04/04/2009 12.02.03 - TextToSpeech::Speak: Could not speak text "you ".

This happens when I try to use TextToSpeech inside the Execute() method of an OSThread object. Inside the thread I create another TextToSpeech object, is that correct?

Anyway the problem arises because my application adopts the MVC design pattern and all the actions when the users hits a target are executed from a single method of the controller. Among these actions there is "speak" and there are also other actions taking long time such as word prediction. The idea was to execute the main controller method in a thread to avoid blocking the pipeline while the actions are running.

tiziano
Posts: 18
Joined: 19 Oct 2008, 10:22

I did it

Post by tiziano » 06 Apr 2009, 13:44

Ok, finally I solved the problem.
Here is the simple trick (for any others who will face this problem):

create a new TextToSpeech object on the stack just before using it, so inside the same thread where speak() is called.

If there are other TextToSpeech instances created in other points of the code, the thing won't work.

gschalk
Posts: 615
Joined: 28 Jan 2003, 12:37

TextToSpeech

Post by gschalk » 06 Apr 2009, 14:41

Tiziano,

Thanks for sharing the solution. That's great.

Gerv

tiziano
Posts: 18
Joined: 19 Oct 2008, 10:22

Post by tiziano » 08 Apr 2009, 17:47

Now that I'm cleaning the repository I realized that TextToSpeech worked with the previous trick but with a small modification:

I've commented out these lines:

if( mpVoice != NULL )
mpVoice->Release();

the problem with this code is that if the internal thread of TextToSpeech is still running when the destructor of TextToSpeech is called the voice is released causing a runtime error.
Unfortunatly this is always the case in my application because the function using TextToSpeech creates the TextToSpeech object, calls the speak() method and then immediatly returns (before speaking is finished).

Locked

Who is online

Users browsing this forum: Google [Bot] and 21 guests