Solved

Text-to_Speech MS Agent 4.0 Question

Posted on 2006-06-18
8
222 Views
Last Modified: 2010-04-24
I am working on the MS Agent 4.0 application and got 2 problems.
1.  How can I change the speaker?  by default, is MSMary and I want to use other user like MSMike
2.  My code is working fine now for MS Mary but when I play a few times, it will crash!  How to solve it?

////////my code/////////////////////
BSTR sIP = ::SysAllocString(L"");
char  key[20];
int i;
TCHAR wsIP[300];
static const LPTSTR kpszAppTitle="";
static const LPWSTR kpwszCharacter = L"orgmerlin.acs";
      HRESULT                        hRes;
      _TCHAR                        szError[256];
      VARIANT                        vPath;
      BSTR                        bszSpeak;
      long                        lCharID;
      long                        lRequestID;
      IAgentEx               *pAgentEx;
      IAgentCharacterEx  *pCharacterEx = NULL;
      ISpObjectToken *pToken = NULL;
      ULONG               ulCount = 0;

hRes = CoCreateInstance(CLSID_AgentServer,NULL,      CLSCTX_SERVER,IID_IAgentEx,      (LPVOID *)&pAgentEx);

            // First try to load the default character

            VariantInit(&vPath);
            vPath.vt = VT_BSTR;
            //vPath.vt = VT_EMPTY;
            vPath.bstrVal = SysAllocString(kpwszCharacter);
            hRes = pAgentEx->Load(vPath, &lCharID, &lRequestID);
        hRes = pAgentEx->GetCharacterEx(lCharID, &pCharacterEx);
        hRes = pCharacterEx->Show(TRUE, &lRequestID);
   hRes = pCharacterEx->SetLanguageID(MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
 bszSpeak = SysAllocString(A2W((LPTSTR)sIP));
pVoice->Speak(bszSpeak, NULL, &lRequestID);
SysFreeString(bszSpeak);
0
Comment
Question by:gorexy
  • 4
  • 4
8 Comments
 
LVL 15

Expert Comment

by:lakshman_ce
ID: 16934437
>>BSTR sIP = ::SysAllocString(L"");
>>bszSpeak = SysAllocString(A2W((LPTSTR)sIP));
>>SysFreeString(bszSpeak);

SysAllocString  allocates a new string and copies the passed string into it. Appears you are calling SysAllocString twice but not freeing it twice.

You can pass sIP to
pVoice->Speak(sIP, NULL, &lRequestID);

Btw where you are assigning the value to sIP?

Also try to debug your application during crash to pin point the problem. Look at the call stack to determine which line of your code is causing the problem.




0
 

Author Comment

by:gorexy
ID: 16934465
thanks
actually sIP will be filled from external progrm (Virtools Dev) and Ihave checked there is content inside.
0
 
LVL 15

Expert Comment

by:lakshman_ce
ID: 16934990
1. For sIP, how you are allocating additional memory. What would be the length of the string from your external program. Inital calling  of SysAllocString has emptry string value for the sIP variable.
2. how the memory is deallocated for sIP
0
 

Author Comment

by:gorexy
ID: 16935108
hm..Ok I will copy my code tomorrow and show you.
0
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

Author Comment

by:gorexy
ID: 16939271
I use this to get input
beh->GetInputParameterValue(0, sIP);
bszSpeak = SysAllocString(A2W((LPTSTR)sIP));
0
 
LVL 15

Accepted Solution

by:
lakshman_ce earned 30 total points
ID: 16941886
Try something like this for correct memory allocation/deallocation for sIP
Btw why do you need another BSTR bszSpeak. You can just use sIP directly.

void GetInputParameterValue(BSTR* sIP)
{
      *sIP = ::SysAllocString(L"Hello");
}

void main()
{
               USES_CONVERSION;
      BSTR sIP;  //don't allocate memory here as the length of the input string from external method may vary
      GetInputParameterValue(&sIP);
      BSTR bszSpeak = SysAllocString(A2W((LPTSTR)sIP));
                //use bszSpeak or sIP
      SysFreeString(sIP); //deallocate the memory allocated for sIP
      SysFreeString(bszSpeak);
}
0
 

Author Comment

by:gorexy
ID: 16956607
ok let me test

how about
How can I change the speaker?  by default, is MSMary and I want to use other user like MSMike
?
0
 
LVL 15

Expert Comment

by:lakshman_ce
ID: 16959740
>>How can I change the speaker?  by default, is MSMary and I want to use other user like MSMike?

I am not sure about that.
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Suggested Solutions

The following diagram presents a diamond class hierarchy: As depicted, diamond inheritance denotes when two classes (e.g., CDerived1 and CDerived2), separately extending a common base class (e.g., CBase), are sub classed simultaneously by a fourt…
In Easy String Encryption Using CryptoAPI in C++ (http://www.experts-exchange.com/viewArticle.jsp?aid=1193) I described how to encrypt text and recommended that the encrypted text be stored as a series of hexadecimal digits -- because cyphertext may…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

707 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now