Solved

Text-to_Speech MS Agent 4.0 Question

Posted on 2006-06-18
8
229 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
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

 

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

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

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 Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

778 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