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

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1266
  • Last Modified:

Seech SDK 5.1 VC++ question

HI,
  I am working with the Speech SDK TTS
I face an error when I want to change the token.

I add this

CComPtr<IEnumSpObjectTokens> cpEnum;
CComPtr<ISpObjectToken> cpToken;

if(SUCCEEDED(hr))
      {
            hr = SpEnumTokens(SPCAT_VOICES, L"Name=Microsoft Sam", NULL, &cpEnum);
      }
   
      
      //set the voice
      if(SUCCEEDED(hr))
      {
            hr = cpVoice->SetVoice( cpToken);
      }

      if(SUCCEEDED(hr))
      {
            hr = cpVoice->SetOutput( NULL, TRUE );
      }

it keeps saying 'CComPtr' : undeclared identifier

what;s wrong?

I tried to include #include <atlbase.h>  but even worst, it shows over 100 errors.
0
gorexy
Asked:
gorexy
  • 26
  • 22
1 Solution
 
chip3dCommented:
hi gorexy,

CComPtr can only be use in an ATL environment. So you have to create an Atl Project or use http://www.codeproject.com/com/ccomptr.asp for non Atl project.

You can also use the _com_ptr_t from comip.h (lib: comsupp.lib)

typedef _com_ptr_t<_com_IIID<ISpObjectToken, &__uuidof(ISpObjectToken)> > ISpObjectTokenPtr;
typedef _com_ptr_t<_com_IIID<IEnumSpObjectTokens, &__uuidof(IEnumSpObjectTokens)> > IEnumSpObjectTokensPtr;

_com_ptr_t automatically query to all supported compobjects, if it fail it will set the pointer to 0.

IEnumSpObjectTokensPtr cpEnum;
hr = SpEnumTokens(SPCAT_VOICES, L"Name=Microsoft Sam", NULL, &cpEnum);
...
0
 
gorexyAuthor Commented:
Hi thanks!
 My code is as follows:

///////////////////////////////////////////////////////////////
#include "CKAll.h"
#include <sapi.h>

.....

int SpeakOut(const CKBehaviorContext& BehContext)
{


      CKBehavior* beh = BehContext.Behavior;

        CComPtr<ISpVoice>              cpVoice;

      beh->ActivateInput(0,FALSE);
      beh->ActivateOutput(0);

         char sIP[300];
      beh->GetInputParameterValue(0, sIP);
                beh->SetOutputParameterValue(0,sIP);


      TCHAR wsIP[300];
      MultiByteToWideChar(CP_ACP, 0, sIP, -1,  (LPWSTR)wsIP, 300);

      //////////////////////////Text to Speech Start/////////////////////////
    ISpVoice * pVoice = NULL;

    HRESULT hr = CoCreateInstance(CLSID_SpVoice, NULL, CLSCTX_ALL, IID_ISpVoice, (void **)&pVoice);


    if( SUCCEEDED( hr ) )
    {
        hr = pVoice->Speak((LPWSTR)wsIP , 0, NULL);
        pVoice->Release();
        pVoice = NULL;
    }

      
      return CKBR_OK;
}


Do you mind to have a look and suggest me how to change it?

I will try your code also
Thanks
0
 
gorexyAuthor Commented:
Errors still

here is my code
///////////////////////////////////////////////////////////

typedef _com_ptr_t<_com_IIID<ISpObjectToken, &__uuidof(ISpObjectToken)> > ISpObjectTokenPtr;
typedef _com_ptr_t<_com_IIID<IEnumSpObjectTokens, &__uuidof(IEnumSpObjectTokens)> > IEnumSpObjectTokensPtr;
typedef _com_ptr_t<_com_IIID<ISpVoice, &__uuidof(ISpVoice)> > ISpVoice cpVoice;

      beh->ActivateInput(0,FALSE);
      beh->ActivateOutput(0);

         char sIP[300];
      beh->GetInputParameterValue(0, sIP);
    //BehContext.Context->OutputToConsoleEx("Set server ip to %s", sIP);
    beh->SetOutputParameterValue(0,sIP);


      TCHAR wsIP[300];
      MultiByteToWideChar(CP_ACP, 0, sIP, -1,  (LPWSTR)wsIP, 300);

      //////////////////////////Text to Speech Start/////////////////////////
    ISpVoice * pVoice = NULL;

    HRESULT hr = CoCreateInstance(CLSID_SpVoice, NULL, CLSCTX_ALL, IID_ISpVoice, (void **)&pVoice);
    IEnumSpObjectTokensPtr cpEnum;
      ISpObjectTokenPtr cpToken;

   if(SUCCEEDED(hr))
      {
            hr = SpEnumTokens(SPCAT_VOICES, L"Name=Microsoft Sam", NULL, &cpEnum);
      }
   
      
      //set the voice
      if(SUCCEEDED(hr))
      {
            hr = cpVoice->SetVoice( cpToken);
      }

      if(SUCCEEDED(hr))
      {
            hr = cpVoice->SetOutput( NULL, TRUE );
      }    if( SUCCEEDED( hr ) )
    {
        hr = pVoice->Speak((LPWSTR)wsIP , 0, NULL);
        pVoice->Release();
        pVoice = NULL;
    }


sorry I am new in this kind of stuff
0
[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.

 
gorexyAuthor Commented:
ok now I try to use the link your provide
and one error only

SpEnumTokens': identifier not found, even with argument-dependent lookup

I search the SDK reference and the function found in #include <sphelper.h>

so I include #include <sphelper.h>

but fail
any suggestion?
0
 
chip3dCommented:
for sapi with _com_ptr_t you need:

#include <comip.h>  // (comsupp.lib)
#include <sapi.h>    //(sapi.lib)
#include <spuihelp.h>

can you post the errormessage please
0
 
chip3dCommented:
ups, sorry, you already posted the error
0
 
gorexyAuthor Commented:
Compiling...
SpeakOut.cpp
c:\Text_Syn\Project1\SpeakOut.cpp(96) : error C2371: 'cpEnum' : redefinition; different basic types
        c:\Text_Syn\Project1\SpeakOut.cpp(73) : see declaration of 'cpEnum'
c:\Text_Syn\Project1\SpeakOut.cpp(97) : error C2371: 'cpToken' : redefinition; different basic types
        c:\Text_Syn\Project1\SpeakOut.cpp(74) : see declaration of 'cpToken'
c:\Text_Syn\Project1\SpeakOut.cpp(101) : error C3861: 'cpEnum': identifier not found, even with argument-dependent lookup
c:\Text_Syn\Project1\SpeakOut.cpp(106) : error C3861: 'cpToken': identifier not found, even with argument-dependent lookup


Project1 - 4 error(s), 0 warning(s)
0
 
chip3dCommented:
>SpEnumTokens': identifier not found, even with argument-dependent lookup

are you sure spuihelp.h is included?
0
 
chip3dCommented:
typedef _com_ptr_t<_com_IIID<ISpObjectToken, &__uuidof(ISpObjectToken)> > ISpObjectTokenPtr;
typedef _com_ptr_t<_com_IIID<IEnumSpObjectTokens, &__uuidof(IEnumSpObjectTokens)> > IEnumSpObjectTokensPtr;
typedef _com_ptr_t<_com_IIID<ISpVoice, &__uuidof(ISpVoice)> > ISpVoice VoicePtr;

     beh->ActivateInput(0,FALSE);
     beh->ActivateOutput(0);

        char sIP[300];
     beh->GetInputParameterValue(0, sIP);
    //BehContext.Context->OutputToConsoleEx("Set server ip to %s", sIP);
    beh->SetOutputParameterValue(0,sIP);


     TCHAR wsIP[300];
     MultiByteToWideChar(CP_ACP, 0, sIP, -1,  (LPWSTR)wsIP, 300);

     //////////////////////////Text to Speech Start/////////////////////////
    VoicePtr cpVoice;

    HRESULT hr = cpVoice.CreateInstance(CLSID_SpVoice);
    IEnumSpObjectTokensPtr cpEnum;
    ISpObjectTokenPtr cpToken;

   if(SUCCEEDED(hr))
     {
          hr = SpEnumTokens(SPCAT_VOICES, L"Name=Microsoft Sam", NULL, &cpEnum);
     }
   
     
     //set the voice
     if(SUCCEEDED(hr))
     {
          hr = cpVoice->SetVoice( cpToken);
     }

     if(SUCCEEDED(hr))
     {
          hr = cpVoice->SetOutput( NULL, TRUE );
     }    if( SUCCEEDED( hr ) )
    {
        hr = cpVoice->Speak((LPWSTR)wsIP , 0, NULL);
    }

    }
0
 
gorexyAuthor Commented:
that is ok

how to initilize cpVoice

typedef _com_ptr_t<_com_IIID<ISpVoice, &__uuidof(ISpVoice)> > ISpVoice cpVoice;
this is wrong
0
 
chip3dCommented:
oh, before you can use cpToken, you have to init or load from enum!

cpEnum->->Item(0, &cpToken );
0
 
chip3dCommented:
>typedef _com_ptr_t<_com_IIID<ISpVoice, &__uuidof(ISpVoice)> > ISpVoice cpVoice;
well, this is ok, but its a typedef, this means if you write cpVoice would be the same as to write _com_ptr_t<_com_IIID<ISpVoice, &__uuidof(ISpVoice)> > like #define...

to declare a pointer just write cpVoice pVoice;
But you later used cpVoice directly, but it is a typefef, no variable.

To be more clrear i changed cpVoice to VoicePtr, like the other typedefs
0
 
chip3dCommented:
cpEnum->->Item(0, &cpToken ); must be cpEnum->Item(0, &cpToken );
0
 
gorexyAuthor Commented:
i am still testing

once ok i will get back to you

BTW, where can I learn more ATL projecT?  I feels confused still
Thanks
0
 
chip3dCommented:
i normally don't use ATL...
here you can find some examples:
http://www.codeguru.com/cpp/com-tech/atl/
0
 
gorexyAuthor Commented:
I don't want to use too
but the SPEECH SDK uses that and we have to follow

I want to change the voice freely and so I need to get the token
The SDK example use ATL and so I follow

will let you know it works or not
Thanks for your help!!
0
 
chip3dCommented:
im sorry, i forgot to metion:
there are two helpers for sapi, the sphelper.h wich requiers no atl and the spuihelp.h wich requires atl.
within sphelper.h there is also all defined you need like SpEnumTokens...
i thought you were using the sphelper.h, so im sorry for not telling you earlier



0
 
chip3dCommented:
The CComPtr than will also work when including sphelper.h
0
 
gorexyAuthor Commented:
HI the code still fails

///////////////////////////////////////////////////////
typedef _com_ptr_t<_com_IIID<ISpObjectToken, &__uuidof(ISpObjectToken)> > ISpObjectTokenPtr;
typedef _com_ptr_t<_com_IIID<IEnumSpObjectTokens, &__uuidof(IEnumSpObjectTokens)> > IEnumSpObjectTokensPtr;
typedef _com_ptr_t<_com_IIID<ISpVoice, &__uuidof(ISpVoice)> > ISpVoice VoicePtr;


      beh->ActivateInput(0,FALSE);
      beh->ActivateOutput(0);

         char sIP[300];
      beh->GetInputParameterValue(0, sIP);
    //BehContext.Context->OutputToConsoleEx("Set server ip to %s", sIP);
    beh->SetOutputParameterValue(0,sIP);


      TCHAR wsIP[300];
      MultiByteToWideChar(CP_ACP, 0, sIP, -1,  (LPWSTR)wsIP, 300);

      //////////////////////////Text to Speech Start/////////////////////////
    ISpVoice * pVoice = NULL;

    HRESULT hr = CoCreateInstance(CLSID_SpVoice, NULL, CLSCTX_ALL, IID_ISpVoice, (void **)&pVoice);
    IEnumSpObjectTokensPtr cpEnum;
      ISpObjectTokenPtr cpToken;
//      ISpVoiceVoicePtr cpVoice;
      VoicePtr cpVoice;

    if(SUCCEEDED(hr))
      {
            hr = SpEnumTokens(SPCAT_VOICES, L"Name=MS Mary", NULL, &cpEnum);
      }      

      if(SUCCEEDED(hr))
      {
            hr = cpVoice->SetVoice( cpToken);
      }

    if( SUCCEEDED( hr ) )
    {
        hr = pVoice->Speak((LPWSTR)wsIP , 0, NULL);
        pVoice->Release();
        pVoice = NULL;
    }

      
      return CKBR_OK;
}

can you have a look?


error message

////////////////////////////////////

c:\Text_Syn\Project1\SpeakOut.cpp(79) : error C2065: 'VoicePtr' : undeclared identifier
c:\Text_Syn\Project1\SpeakOut.cpp(101) : error C2146: syntax error : missing ';' before identifier 'cpVoice'
c:\Text_Syn\Project1\SpeakOut.cpp(101) : error C3861: 'VoicePtr': identifier not found, even with argument-dependent lookup
c:\Text_Syn\Project1\SpeakOut.cpp(101) : error C2065: 'cpVoice' : undeclared identifier
c:\Text_Syn\Project1\SpeakOut.cpp(110) : error C2227: left of '->SetVoice' must point to class/struct/union
        type is ''unknown-type''
c:\Text_Syn\Project1\SpeakOut.cpp(110) : error C3861: 'cpVoice': identifier not found, even with argument-dependent lookup
c:\Text_Syn\Project1\SpeakOut.cpp(115) : error C2039: 'Speak' : is not a member of '_com_ptr_t<_IIID>'
        with
        [
            _IIID=_com_IIID<ISpVoice,& _GUID_6c44df74_72b9_4992_a1ec_ef996e0422d4>
        ]
Project1.cpp
MyManager.cpp
Generating Code...
0
 
gorexyAuthor Commented:
Pls ignore my previous message
here is teh lastest code

#include "CKAll.h"
#include <sapi.h>
#include <comip.h>  // (comsupp.lib)
#include <spuihelp.h>

...

int SpeakOut(const CKBehaviorContext& BehContext)
{

      
      CKBehavior* beh = BehContext.Behavior;

typedef _com_ptr_t<_com_IIID<ISpObjectToken, &__uuidof(ISpObjectToken)> > ISpObjectTokenPtr;
typedef _com_ptr_t<_com_IIID<IEnumSpObjectTokens, &__uuidof(IEnumSpObjectTokens)> > IEnumSpObjectTokensPtr;
typedef _com_ptr_t<_com_IIID<ISpVoice, &__uuidof(ISpVoice)> > ISpVoice VoicePtr;



      beh->ActivateInput(0,FALSE);
      beh->ActivateOutput(0);

         char sIP[300];
      beh->GetInputParameterValue(0, sIP);
                 beh->SetOutputParameterValue(0,sIP);


      TCHAR wsIP[300];
      MultiByteToWideChar(CP_ACP, 0, sIP, -1,  (LPWSTR)wsIP, 300);
    VoicePtr cpVoice;
      //////////////////////////Text to Speech Start/////////////////////////

      HRESULT hr = cpVoice.CreateInstance(CLSID_SpVoice);
               IEnumSpObjectTokensPtr cpEnum;
      ISpObjectTokenPtr cpToken;
      
    if(SUCCEEDED(hr))
      {
            hr = SpEnumTokens(SPCAT_VOICES, L"Name=MS Mary", NULL, &cpEnum);
      }      

      if(SUCCEEDED(hr))
      {
            
            hr = cpVoice->SetVoice( cpToken);
      }

     if(SUCCEEDED(hr))
     {
          hr = cpVoice->SetOutput( NULL, TRUE );
     }    if( SUCCEEDED( hr ) )
    {
        hr = cpVoice->Speak((LPWSTR)wsIP , 0, NULL);
    }


      return CKBR_OK;
}

Error message

SpeakOut.cpp
c:\Text_Syn\Project1\SpeakOut.cpp(79) : error C2146: syntax error : missing ';' before identifier 'VoicePtr'
c:\Text_Syn\Project1\SpeakOut.cpp(79) : error C2065: 'VoicePtr' : undeclared identifier
c:\Text_Syn\Project1\SpeakOut.cpp(94) : error C2146: syntax error : missing ';' before identifier 'cpVoice'
c:\Text_Syn\Project1\SpeakOut.cpp(94) : error C3861: 'VoicePtr': identifier not found, even with argument-dependent lookup
c:\Text_Syn\Project1\SpeakOut.cpp(94) : error C2065: 'cpVoice' : undeclared identifier
c:\Text_Syn\Project1\SpeakOut.cpp(99) : error C2228: left of '.CreateInstance' must have class/struct/union type
        type is ''unknown-type''
c:\Text_Syn\Project1\SpeakOut.cpp(99) : error C3861: 'cpVoice': identifier not found, even with argument-dependent lookup
c:\Text_Syn\Project1\SpeakOut.cpp(113) : error C2227: left of '->SetVoice' must point to class/struct/union
        type is ''unknown-type''
c:\Text_Syn\Project1\SpeakOut.cpp(113) : error C3861: 'cpVoice': identifier not found, even with argument-dependent lookup
c:\Text_Syn\Project1\SpeakOut.cpp(126) : error C2227: left of '->SetOutput' must point to class/struct/union
        type is ''unknown-type''
c:\Text_Syn\Project1\SpeakOut.cpp(126) : error C3861: 'cpVoice': identifier not found, even with argument-dependent lookup
c:\Text_Syn\Project1\SpeakOut.cpp(129) : error C2227: left of '->Speak' must point to class/struct/union
        type is ''unknown-type''
c:\Text_Syn\Project1\SpeakOut.cpp(129) : error C3861: 'cpVoice': identifier not found, even with argument-dependent lookup
Project1.cpp
MyManager.cpp
Generating Code...
0
 
gorexyAuthor Commented:
In fact, I found that we can program MS Agent and it supports many language
Is it possible for us to combine that agent in the Speech SDK in order to develop multi language application>?
0
 
chip3dCommented:
#include "CKAll.h"
#include <comip.h>  // (comsupp.lib)
#include <sphelper.h>  // use sphelper not spuihelp (sapi.h also included)

int SpeakOut(const CKBehaviorContext& BehContext)
{

     
     CKBehavior* beh = BehContext.Behavior;

     typedef _com_ptr_t<_com_IIID<ISpObjectToken, &__uuidof(ISpObjectToken)> > ISpObjectTokenPtr;
     typedef _com_ptr_t<_com_IIID<IEnumSpObjectTokens, &__uuidof(IEnumSpObjectTokens)> > IEnumSpObjectTokensPtr;
     typedef _com_ptr_t<_com_IIID<ISpVoice, &__uuidof(ISpVoice)> > ISpVoicePtr;  // sorry, this line still wasn't correct.



     beh->ActivateInput(0,FALSE);
     beh->ActivateOutput(0);

     char sIP[300];
     beh->GetInputParameterValue(0, sIP);
     beh->SetOutputParameterValue(0,sIP);


     TCHAR wsIP[300];
     MultiByteToWideChar(CP_ACP, 0, sIP, -1,  (LPWSTR)wsIP, 300);
     ISpVoicePtr cpVoice;
     //////////////////////////Text to Speech Start/////////////////////////

     HRESULT hr = cpVoice.CreateInstance(CLSID_SpVoice);
     IEnumSpObjectTokensPtr cpEnum;
     ISpObjectTokenPtr cpToken;
     
    if(SUCCEEDED(hr))
     {
          hr = SpEnumTokens(SPCAT_VOICES, L"Name=Microsoft Mary", NULL, &cpEnum);  // MS Mary was not found by my system
     }    

     // cpToken is still empty, first load token from cpEnum
     if(SUCCEEDED(hr))
     {
          hr = cpEnum->Item(0, &cpToken);
     }

     if(SUCCEEDED(hr))
     {    
          hr = cpVoice->SetVoice(cpToken);
     }

     if(SUCCEEDED(hr))
     {
          hr = cpVoice->SetOutput( NULL, TRUE );
     }    if( SUCCEEDED( hr ) )
    {
        hr = cpVoice->Speak((LPWSTR)wsIP , 0, NULL);
    }


     return CKBR_OK;
}


hi, compiled this code without CKBehaviorContext and its working on my machine...
0
 
gorexyAuthor Commented:
i got this

unresolved external symbol "void __stdcall _com_issue_error(long)"
0
 
gorexyAuthor Commented:
then I wrote

//Alex Added Here
      
      CKBehavior* beh = BehContext.Behavior;
/*       CComPtr<ISpVoice>              cpVoice;
      CComPtr<IEnumSpObjectTokens> cpEnum;
      CComPtr<ISpObjectToken> cpToken;*/
CComPtr<ISpVoice>              cpVoice;
CComPtr<IEnumSpObjectTokens> cpEnum;

//typedef _com_ptr_t<_com_IIID<ISpVoice, &__uuidof(ISpVoice)> > ISpVoiceVoicePtr;
typedef _com_ptr_t<_com_IIID<ISpObjectToken, &__uuidof(ISpObjectToken)> > ISpObjectTokenPtr;
//typedef _com_ptr_t<_com_IIID<IEnumSpObjectTokens, &__uuidof(IEnumSpObjectTokens)> > IEnumSpObjectTokensPtr;
//typedef _com_ptr_t<_com_IIID<ISpVoice, &__uuidof(ISpVoice)> > ISpVoicePtr;



      beh->ActivateInput(0,FALSE);
      beh->ActivateOutput(0);

         char sIP[300];
      beh->GetInputParameterValue(0, sIP);
    //BehContext.Context->OutputToConsoleEx("Set server ip to %s", sIP);
    beh->SetOutputParameterValue(0,sIP);


      TCHAR wsIP[300];
      MultiByteToWideChar(CP_ACP, 0, sIP, -1,  (LPWSTR)wsIP, 300);
    //ISpVoiceVoicePtr cpVoice;
      //////////////////////////Text to Speech Start/////////////////////////
  // ISpVoice * pVoice = NULL;
//ISpVoicePtr  cpVoice=NULL;
   // HRESULT hr = CoCreateInstance(CLSID_SpVoice, NULL, CLSCTX_ALL, IID_ISpVoice, (void **)&pVoice);
      HRESULT hr = cpVoice.CoCreateInstance(CLSID_SpVoice);
   // IEnumSpObjectTokensPtr cpEnum;
      ISpObjectTokenPtr cpToken;
      
      
  // cpEnum->Item(0, &cpToken );
    if(SUCCEEDED(hr))
      {
      //      hr = SpEnumTokens(SPCAT_VOICES, L"Name=Microsoft Simplified Chinese", NULL, &cpEnum);
            hr = SpEnumTokens(SPCAT_VOICES, L"Name=Microsoft Simplified Chinese",  NULL, &cpEnum);

    }
      //Get the closest token
      if(SUCCEEDED(hr))
      {
          hr = cpEnum ->Next(1, &cpToken, NULL);
      }
   
      if(SUCCEEDED(hr))
      {
            
            hr = cpVoice->SetVoice( cpToken);
      }
      //set the output to the default audio device

  /*  if( SUCCEEDED( hr ) )
    {
        hr = pVoice->Speak((LPWSTR)wsIP , 0, NULL);
        pVoice->Release();
        pVoice = NULL;

    }*/

      if(SUCCEEDED(hr))
     {
          hr = cpVoice->SetOutput( NULL, TRUE );
     }    
      
       if( SUCCEEDED( hr ) )
     {
        hr = cpVoice->Speak((LPWSTR)wsIP , 0, NULL);


//            cpVoice->Release();
      //  cpVoice = NULL;
     }

      return CKBR_OK;
0
 
gorexyAuthor Commented:
it works

BTW, do you know can we program MS Agent? but I want to hide the characters but can still perform the same TTS as the above code
0
 
chip3dCommented:
>unresolved external symbol "void __stdcall _com_issue_error(long)
looks like you forgot to add the comsupp.lib in the project dependencies
0
 
chip3dCommented:
sorry, i never used MS Agent...
i only know the ms Agent is using sapi4 for TTS
0
 
gorexyAuthor Commented:
I have to try tmr about the comsupp.lib

so I will try to dig out the MS Agent and try to combine with my code and see it can produce different language or not.

Hope you can still help
0
 
chip3dCommented:
well sapi5 does support different languages...
it depends on the voice you are choosing. You also can use the voices of the MS Agent, but than you have to use the sapi4 interface, cuz the voices MS Agent is using are sapi4.
You can get the language code id of a sapi5 voice from its token:

#include <sstream>
#include <algorithm>
typedef long int32;
...

        std::vector<int32> getLcids(const ISpObjectTokenPtr& token)
        {
            // get lcids as string seperated with ";"
            ISpDataKeyPtr attrib;
            if (token->OpenKey(L"Attributes", &attrib) != S_OK) return         std::vector<int32>();
            wchar_t * dstr = 0;
            std::wstring str;
            if (attrib->GetStringValue(L"Language",&dstr) == S_OK)
                str= dstr;
            CoTaskMemFree(dstr);
           
            // seperate strings and convert to int32
            std::vector<int32> ret;
            if (str.empty()) return ret;
            std::vector<std::wstring> v;
            typedef std::wstring::const_iterator iter;

            iter i = str.begin();
            while (i != str.end()) {

                  // ignore leading blanks
                  i = find_if(i, str.end(), non_sc);

                  // find end of next word
                  iter j = find_if(i, str.end(), is_sc);

                  // copy the characters in `[i,' `j)'
                  if (i != str.end())
                    v.push_back(std::wstring(i, j));
                  i = j;
            }

           
            if (v.empty()) return ret;
            for (std::vector<std::wstring>::const_iterator iter = v.begin(); iter != v.end(); ++iter)
            {
                std::wistringstream sstr(*iter);
                int32 tmp;
                sstr >> std::hex >> tmp;
                ret.push_back(tmp);
            }
            return ret;
        }
0
 
gorexyAuthor Commented:
hi
"well sapi5 does support different languages..."
Are you sure?  I read the specification of the SDK, and it said for TTS, only supported Simple Chinese and English.  That's why I want to use MS Agent.
If so it is a good news, how to do it?

Your code can do so?
let me read first...
0
 
gorexyAuthor Commented:
In my code, I try to get the toketn (ie. get different languages) already but I assume that user installed the TTS Language pack in their computer and so my system contains only English and Simply Chinese TTS which can be found in the registry key.

So you said we SAPI support different language, do we need to install anything? MS Agent?
0
 
chip3dCommented:
well,
the default sapi5 languages installed with windows are only english. but there are many tts modules for sapi4/sapi5 from different companys. Most of them not for free (particularly the high quality voices and sapi5 voices). For sapi4 you will get many free voices from the internet (like the one form MS Agent: http://www.microsoft.com/msagent/downloads/user.asp#tts).
If you want to use both, you need a interface that can work with sapi4 and sapi5. In this case you have to write an abstaction layer for the function you need and implement them for the sapi4 and sapi5 interface.
0
 
gorexyAuthor Commented:
oh too complicated to me.

hm...if MS Agent can provide different languages, I prefer to develop the SAPI4
let see how it works...

Do you mind to tell me what is the best way to learn VC++?  I found it is quite hard to manage.
0
 
gorexyAuthor Commented:
This is  the code from MS Agent
Before I try to modify it, do you think it doesn't load the character and it can still read a text, say from a textbox, and it can pronounce?

#ifndef STRICT
#define STRICT
#endif


//==========================================================================
//
//  THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
//  KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
//  IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR
//  PURPOSE.
//
//  Copyright (C) 1997-1998 Microsoft Corporation.  All Rights Reserved.
//
//--------------------------------------------------------------------------
//
// This sample demonstrates the simplest Microsoft Agent application
//
//==========================================================================


#include <windows.h>
#include <tchar.h>
#include "AgtSvr.h"
#include "AgtSvr_i.c"


static const LPWSTR kpwzCharacterOld = L"\\program files\\microsoft agent\\characters\\genie.acs";
static const LPTSTR kpszAppTitle = _T("Microsoft Agent Samples");


extern "C" int PASCAL WinMain(HINSTANCE hInst,
                                            HINSTANCE hInstPrev,
                                            LPSTR lpCmdLine,
                                            int nCmdShow) {

      HRESULT                        hRes;
      _TCHAR                        szError[256];
      VARIANT                        vPath;
      BSTR                        bszSpeak;
      long                        lCharID;
      long                        lRequestID;
      IAgentEx               *pAgentEx;
      IAgentCharacterEx  *pCharacterEx = NULL;
      
      // Initialize COM

    if (FAILED(CoInitialize(NULL))) {
            MessageBox(NULL,
                           _T("There was an error initializing COM."),
                           kpszAppTitle,
                           MB_OK | MB_ICONERROR);
        return -1;
      }

      // Create an instance of the Agent 2.0 server. NOTE: by
      // asking for an IAgentEx interface we know we will get
      // at least Agent 2.0. The CLSID also changed between
      // 1.5 and 2.0 so we know we won't get the 1.5 server.

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

            wsprintf(szError, _T("There was an error initializing Microsoft Agent, code = 0x%x"), hRes);

            MessageBox(NULL,
                           szError,
                           kpszAppTitle,
                           MB_OK | MB_ICONERROR | MB_TOPMOST);
      
            CoUninitialize();

            return -1;
      }

      __try {

            // First try to load the default character

            VariantInit(&vPath);
            vPath.vt = VT_EMPTY;

             hRes = pAgentEx->Load(vPath, &lCharID, &lRequestID);

            if (FAILED(hRes)) {

                  // There's no default character. See if we can load the
                  // character from the directory used in most version 1.5
                  // applications.

                  vPath.vt = VT_BSTR;
                  vPath.bstrVal = SysAllocString(kpwzCharacterOld);

                  if (vPath.bstrVal == NULL) {
                        hRes = E_OUTOFMEMORY;
                        __leave;
                  }

                  hRes = pAgentEx->Load(vPath, &lCharID, &lRequestID);

                  // Did we successfully load a character?

                  if (FAILED(hRes))
                        __leave;
            }

            // Get the IAgentCharacterEx interface

            hRes = pAgentEx->GetCharacterEx(lCharID, &pCharacterEx);

            if (FAILED(hRes))
                  __leave;

            // Set the language of the character

            hRes = pCharacterEx->SetLanguageID(MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));

            if (FAILED(hRes))
                  __leave;

            // Show the character.  The first parameter tells Microsoft
            // Agent to show the character by playing an animation.

            hRes = pCharacterEx->Show(FALSE, &lRequestID);

            if (FAILED(hRes))
                  __leave;

            // Make the character speak

            bszSpeak = SysAllocString(L"Hello World!");

            hRes = pCharacterEx->Speak(bszSpeak, NULL, &lRequestID);

            SysFreeString(bszSpeak);

            if (FAILED(hRes))
                  __leave;

            // This is a very simplistic sample.  Sleep for 10 seconds
            // and then die.

            Sleep(10000);

      }
      __finally {

            if (FAILED(hRes)) {

                  wsprintf(szError, _T("An error occurred in Microsoft Agent, code = 0x%x"), hRes);

                  MessageBox(NULL,
                                 szError,
                                 kpszAppTitle,
                                 MB_OK | MB_ICONERROR | MB_TOPMOST);
            }
      }

      // Clean up

      if (pCharacterEx) {

            // Release the character interface

            pCharacterEx->Release();

            // Unload the character.  NOTE:  releasing the character
            // interface does NOT make the character go away.  You must
            // call Unload.

            pAgentEx->Unload(lCharID);
      }
      
      // Release the Agent

      pAgentEx->Release();

      VariantClear(&vPath);

      CoUninitialize();

      return 0;
}
0
 
chip3dCommented:
just search google or in the expert-exchange database for "lerning c++"
0
 
chip3dCommented:
You can try to call the Speak function with hidden character:
         ...
           // don't show the character
           //hRes = pCharacterEx->Show(FALSE, &lRequestID);

          //if (FAILED(hRes))
          //     __leave;

          // Make the character speak

          bszSpeak = SysAllocString(L"Hello World!");

          hRes = pCharacterEx->Speak(bszSpeak, NULL, &lRequestID);

          SysFreeString(bszSpeak);
...
0
 
gorexyAuthor Commented:
thanks for your advice for learning C++.  C++ is OK but VC++ is hard  It added many extra codes

So let me try to combine my code with this MS Agent and see it can work out on differnet languages or not.

I think it should be ok, right?  (I don't have strong confidence actually haha)
0
 
chip3dCommented:
first try the demo with the hidden character if it is speaking...
0
 
gorexyAuthor Commented:
I don't know why my MS  Agent cannot work
The agent jumps out but no sound

and your code is working because it doesn't jump out (but i can see a small icon in the tray, it is ok)
still figure out what happen
0
 
gorexyAuthor Commented:
finally it sounds.

but when I hide the wizard, no sound appears
0
 
chip3dCommented:
sorry, i compiled the agent source, it is working but only when visible. I found no way to let it speak invisible.

its also not a good solution to use the agent just to perfrom a tts output.
http://www.microsoft.com/speech/download/old/sdk40a.asp
here you will geht the sapi4 sdk
0
 
gorexyAuthor Commented:
>unresolved external symbol "void __stdcall _com_issue_error(long)
looks like you forgot to add the comsupp.lib in the project dependencies

This works well now!!! Thanks

I am working on the SAPI4 to different languages  
Hope it works
0
 
gorexyAuthor Commented:
HI Chip3d
do you mind to have a look of my new question?
0
 
chip3dCommented:
no, maybe you should open a new Question for this...
0
 
gorexyAuthor Commented:
I opened already and posted here for a few days alredy

0
 
chip3dCommented:
ups, sorry, i havent recognized
0
 
gorexyAuthor Commented:
so u see the post, right?
i find strange that in the Await question area, I cannot see my post
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 26
  • 22
Tackle projects and never again get stuck behind a technical roadblock.
Join Now