Kinect开发笔记之二——语音识别

来源:互联网 发布:linux命令行 删除 编辑:程序博客网 时间:2024/06/13 19:49

个人觉得Kinect的语音识别还是做得不错的,不过支持的7国语言居然没有汉语,所以只能用英语了。其实Kinect的demo里面有一个语音识别的demo,是控制一只龟运动的,所以我也没必要在说太多了,只是稍微说一些注意地方好了。

  • 1、无论是安装sdk好,还是runtime platform最好下一步到底,不要改路径了,装C盘就C盘就是了。

  • 2、如果你想除了语音识别,还想TTS朗读的话,建议不要用微软建议的Microsoft Speech Platform 11,是朗读不出声的,我用的是win10,用VS2013 自带的sdk8.1就行了。

  • 3、下面的就是关键代码:

void SpeechThread::ProcessSpeech(){    const float ConfidenceThreshold = 0.3f; //阈值,大一点就准确一点    SPEVENT curEvent = { SPEI_UNDEFINED, SPET_LPARAM_IS_UNDEFINED, 0, 0, 0, 0 };    ULONG fetched = 0;    HRESULT hr = S_OK;    m_pSpeechContext->GetEvents(1, &curEvent, &fetched);    while (fetched > 0)    {        switch (curEvent.eEventId)        {        case SPEI_RECOGNITION:            if (SPET_LPARAM_IS_OBJECT == curEvent.elParamType)            {                // this is an ISpRecoResult                ISpRecoResult* result = reinterpret_cast<ISpRecoResult*>(curEvent.lParam);                SPPHRASE* pPhrase = NULL;                hr = result->GetPhrase(&pPhrase);                if (SUCCEEDED(hr))                {                    if ((pPhrase->pProperties != NULL) && (pPhrase->pProperties->pFirstChild != NULL))                    {                        const SPPHRASEPROPERTY* pSemanticTag = pPhrase->pProperties->pFirstChild;                        if (pSemanticTag->SREngineConfidence > ConfidenceThreshold)                        {                            wcout << pSemanticTag->pszValue << endl;                            CString str;                            str=pSemanticTag->pszValue;                            CWnd *pWnd = CWnd::FindWindow(NULL, _T("SpeechIdentify"));//获取目标窗口                            pWnd->SendMessage(SPEECH_EVENT, 0, (LPARAM)str.AllocSysString());//发送消息                        }                    }                    ::CoTaskMemFree(pPhrase);                }            }            break;        }        m_pSpeechContext->GetEvents(1, &curEvent, &fetched);    }    return;}
  • 4、因为微软的demo是win32的,所以你要移植到MFC必须开线程。
0 0