qt 實現文字轉語音

void Voice::say(const char *text)
{
    if (m_bSound)
    {
        m_pVoice = NULL;
        if (FAILED(::CoInitialize(NULL)));
        //獲取SpVoice接口
        HRESULT hr = CoCreateInstance(CLSID_SpVoice,NULL,CLSCTX_ALL,IID_ISpVoice,(void**)&m_pVoice);
        if(m_pVoice == NULL) return;
        TCHAR change[256] = {0};         
        int wideLen = MultiByteToWideChar(CP_ACP,0,text,strlen(text),change,0);
        int ret = MultiByteToWideChar(CP_ACP,0,text,strlen(text),change,wideLen);
        int err = GetLastError();           
        TCHAR *temp = change;
        m_pVoice->SetRate(-1);
        m_pVoice->Speak(change,SPF_ASYNC,NULL);
    }
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章