[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Very odd SAPI 5.1 Text2Speech problem

Posted on 2004-11-08
12
Medium Priority
?
356 Views
Last Modified: 2013-11-20
Hello,

I have a very weird Problem with the SAPI text to speech interface:

I use the Text2Speech API in a  MDI MFC application. I have a little toolwindow (Dialogbased) that "speaks" out text via the SAPI and visualizes the spoken text. The text is sent by the active MDI Childwindow to the dialog via a Registered Window Message.

Here is the code, the problem is described below:

BOOL CVoiceDlg::InitSAPI()
{

      if(FAILED(CoInitialize(NULL))) {
            
            m_strError=_T("Error intialization COM");
            return FALSE;
      }

    HRESULT hRes;
      
      hRes = IpVoice.CoCreateInstance(CLSID_SpVoice);
      
      if(FAILED(hRes)) {
            m_strError=_T("Error creating voice");
            return FALSE;
      }
      
      hRes = IpVoice->SetInterest(SPFEI(SPEI_VISEME), SPFEI(SPEI_VISEME));      

      if(FAILED(hRes)) {

            m_strError=_T("Error creating interest.");
            return FALSE;
      }
      
      hRes = IpVoice->SetNotifyWindowMessage(m_hWnd, WM_RECOEVENT, 0, 0);
      
      if(FAILED(hRes)) {

            m_strError=_T("Error setting notification window");
            return FALSE;
      }

      return TRUE;
}

// This is a test function
void CVoiceDlg::OnBtnClickedTest()
{

      if(!m_strError.IsEmpty() || !IsWindowVisible()) return;

      SpeakChat("squish.squash.the.debug.rat.494_00000", "This is a test", FALSE);
}

// This handles the Registered Window-Message
LRESULT CVoiceDlg::OnSpeak(WPARAM wParam, LPARAM lParam)
{

      CString strName = ((EXT_MSG_STRUCT*)lParam)->lpszParam;
      CString strText  = ((EXT_MSG_STRUCT*)lParam)->lpszMsg;
      SpeakChat(strName, strText, (BOOL)wParam);
      return 1;
}

void CVoiceDlg::SpeakChat(CString strName, CString strText, BOOL bAction)
{

      if(!m_strError.IsEmpty() || !IsWindowVisible()) return;

      if(bAction){

            strOut = strName + " " + strText;
      }
      else{

            strOut = strName + " says: " + strText;
      }

      TRACE("SpeakChat: %s\n", strOut);

      IpVoice->Speak(strOut.AllocSysString(), SPF_ASYNC, NULL);      
}



Here the problem:

When SpeakChat is called from the OnBtnClickTest() method, it works correctly,
but if it is called from the OnSpeak(...) method, it reads the text out twice:

One time with punctuations in the form strName + " " +  strMsg and one time, without
punctioations with the bAction condition handled correctly. The first time, the visualization of the
speech, does not work, the second time it does.

I have verified, that the Window message is send correctly (only once).
0
Comment
Question by:Bender979
  • 6
  • 4
11 Comments
 
LVL 45

Expert Comment

by:AndyAinscow
ID: 12524610
Put a breakpoint in your SpeakChat function and see where the first/second call is coming from.
0
 

Author Comment

by:Bender979
ID: 12525258
Does not work, the execution does not break there. I have a TRACE statement in that function though, whih is printed out only once on the debug trace...
0
 
LVL 45

Expert Comment

by:AndyAinscow
ID: 12526390
Does not work, the execution does not break there.

If the breakpoint isn't reached then your function is not being called!!!
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:Bender979
ID: 12526885
It is called, as the TRACE does put the text on the console. Why it does not break there is really beyond me.
0
 

Author Comment

by:Bender979
ID: 12526983
OK, my fault, it does break...

However it only breaks once so it is only called once.

BUT this call:

IpVoice->Speak(strText.AllocSysString(), SPF_ASYNC, NULL);

is blocking, regardless of the SPF_ASYNC flag. Additionally it speaks as if the SPF_NLP_SPEAK_PUNC flags was specified.

When the Speak call exits, It speaks the text out again (this time not blocking) and without speaking the punctuations.

Microsoft SAPI SDK 5.1
Microsoft Visual C++ 7.1

Could this be a compiler bug?

0
 

Author Comment

by:Bender979
ID: 12527421
And it gets even weirder (do you believe in ghosts?):

if I change the code in the method

SpeakChat(CString strName, CString strText, BOOL bAction)

 to:

------- snip ------------

strText = "Why does this not work";
IpVoice->Speak(strText.AllocSysString(), SPF_ASYNC, NULL);

------- snip ------------

It still reads out strName + " " + strMsg;
and after that it reads out "Why does this not work"

This is really the one and only time IpVoice->Speak is called in the entire project.

I cleaned the intermediate files, tried a clean configuration to avoid any wrong compiler/project settings, even in a seperate project it behaves the same. I am totally lost and frustrated :-(
0
 
LVL 45

Expert Comment

by:AndyAinscow
ID: 12527451
I'm no expert with the text to speech interface.  I don't think I can offer anything further.
0
 

Author Comment

by:Bender979
ID: 12554113
Oh my, anyone?

It get's even weirder:

even if I change the function to

void CVoiceDlg::SpeakChat(CString strName, CString strText, BOOL bAction)
{

}

so it does nothing, it still speaks strOut + " " + strText;
0
 
LVL 45

Expert Comment

by:AndyAinscow
ID: 12554395
Do you have this    strOut + " " + strText;  anywhere else in the project?  If you do put a breakpoint there and see if it is somehow being called by this speech out routine.
0
 

Author Comment

by:Bender979
ID: 12602414
Solved by reinstalling the SAPI... I hate that...
0
 

Accepted Solution

by:
CetusMOD earned 0 total points
ID: 12638365
Question PAQ'd
500 points refunded.

CetusMOD
Community Support Moderator
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Suggested Courses

873 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question