Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Text-to_Speech MS Agent 4.0 Question

Posted on 2006-06-18
8
Medium Priority
?
266 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
Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

 

Author Comment

by:gorexy
ID: 16935108
hm..Ok I will copy my code tomorrow and show you.
0
 

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 120 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

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

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

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…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses

810 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