?
Solved

Text-to_Speech MS Agent 4.0 Question

Posted on 2006-06-18
8
Medium Priority
?
253 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 

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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

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 tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses
Course of the Month14 days, 23 hours left to enroll

771 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