• 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/
  • 相关阅读:
    Java包(package)详解
    linux下c++sleep函数
    c++ 一个cpp文件如何调用另一个cpp文件已经定义的类?我不想重复定义
    c++ 断言
    C++类指针初始化
    面向对象编程
    CentOS 下通过命令登录Mysql
    (总结)CentOS Linux使用crontab运行定时任务详解
    【工具】Homebrew的安装及使用
    c++
  • 原文地址:https://www.cnblogs.com/muzizongheng/p/3166582.html
Copyright © 2020-2023  润新知