zoukankan      html  css  js  c++  java
  • TTS API 使用


    #define SPCAT_VOICES           L"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Speech\Voices"
    #define SPKEY_ATTRIBUTES         L"Attributes"
    #define SPVALUE_LANGUAGE         L"Language"
    BOOL CActionCenter::InitializeSAPI()
    {
          ReleaseSAPI();

          HRESULT hr;

          hr = m_cpVoice.CoCreateInstance( CLSID_SpVoice );
          if(hr == S_OK)
          {
                ISpObjectToken * pToken;        // NOTE:  Not a CComPtr!  Be Careful.
                CComPtr<IEnumSpObjectTokens> cpEnum;
                hr = SpEnumTokens(SPCAT_VOICES, L"", L"", &cpEnum);
                if (hr == S_OK)
                {
                      bool fSetDefault = false;
                      while (cpEnum->Next(1, &pToken, NULL) == S_OK)
                      {
                            //CSpDynamicString dstrDesc;
                            //hr = SpGetDescription(pToken, &dstrDesc);
                            //if (SUCCEEDED(hr))
                            {
                                  m_vecISpToken.push_back(pToken);
                            }

                      }

                      return (m_vecISpToken.size() > 0);
                }
          }

          return FALSE;
    }

    void CActionCenter::ReleaseSAPI()
    {
          vector<ISpObjectToken*>::iterator it;

          for(it=m_vecISpToken.begin(); it!=m_vecISpToken.end(); ++it)
          {
                (*it)->Release();
          }

          m_vecISpToken.clear();
    }

    void CActionCenter::SetVoice(LANGID lid)
    {
          vector<ISpObjectToken*>::iterator it;

          WCHAR wstrLangID[32] = {0};
          swprintf(wstrLangID, L"%X", lid);

          for(it=m_vecISpToken.begin(); it!=m_vecISpToken.end(); ++it)
          {
                ISpObjectToken *pToken = (*it);

                ISpDataKey *pSpDataKeyAttributes = NULL;
                HRESULT hr = pToken->OpenKey(SPKEY_ATTRIBUTES, &pSpDataKeyAttributes);
                if(SUCCEEDED(hr))
                {
                      WCHAR *wstrLanguageID = NULL;
                      hr = pSpDataKeyAttributes->GetStringValue(SPVALUE_LANGUAGE, (WCHAR**)&wstrLanguageID);
                      if(SUCCEEDED(hr))
                      {
                            if(wcsstr((BSTR)wstrLanguageID, (BSTR)wstrLangID))
                            {
                                  m_cpVoice->SetVoice(pToken);
                                  break;
                            }

                      }

                      pSpDataKeyAttributes->Release();
                }

          }
    }
    https://muzizongheng.blog.csdn.net/
  • 相关阅读:
    剑指offer系列——56.删除链表中重复的结点
    剑指offer系列——55.链表中环的入口结点
    剑指offer系列——54.字符流中第一个不重复的字符
    剑指offer系列——53.表示数值的字符串
    MinGW与Cygwin
    Android-x86虚拟机安装配置全攻略
    linux下使用NFS挂载文件系统
    ubuntu 64bit “arm-linux-gcc: No such file or directory”问题的解决方法
    虚拟机下ubuntu的minicom使用指南
    Linux 下编译、安装、配置 QT
  • 原文地址:https://www.cnblogs.com/muzizongheng/p/3166582.html
Copyright © 2011-2022 走看看