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
threaded TextToSpeech
Bug?
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
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
still problems
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.
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.
I did it
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.
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.
TextToSpeech
Tiziano,
Thanks for sharing the solution. That's great.
Gerv
Thanks for sharing the solution. That's great.
Gerv
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).
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).
Who is online
Users browsing this forum: Google [Bot] and 21 guests