语音检测与mapx相结合

来源:互联网 发布:京东数据罗盘 编辑:程序博客网 时间:2024/04/30 17:18

由于mapx5.0.x 版本中有存在中文支持的问题,希望将中文转换成拼音,然后再在mapx通过search()检索地名,本列通过isChineseChar()函数判定输入的语音是否是汉字,决定是否是在地图上显示地点,这样可以用与声音判定,比方根据语音命令执行特定的功能,还会继续学习下去

void CSpeechDlg::OnRecoEvent()
{
 USES_CONVERSION;
    CSpEvent event;

    // Process all of the recognition events
    while (event.GetFrom(m_cpRecoCtxt) == S_OK)
    {
        switch (event.eEventId)
        {
            case SPEI_SOUND_START:        
                 m_bSound = TRUE;
                 break;

            case SPEI_SOUND_END:
    {
                 if (m_bSound)
                 {
                    m_bSound = FALSE;
                    if (!m_bReco)
                    {
                        // The sound has started and ended,
                        // but the engine has not succeeded in recognizing anything
      const TCHAR szNoise[] = _T("<noise>");
                        m_edit=szNoise;
      UpdateData(FALSE);
      //::SendDlgItemMessage( m_hDlg, IDC_EDIT_DICT,
      // EM_REPLACESEL, TRUE, (LPARAM) szNoise );
     
                    }
    
                    m_bReco = FALSE;
    
                }
    }
                break;

            case SPEI_RECOGNITION:
                // There may be multiple recognition results, so get all of them
                {
                    m_bReco = TRUE;
                    static const WCHAR wszUnrecognized[] = L"<Unrecognized>";

                    CSpDynamicString dstrText;
                    if (FAILED(event.RecoResult()->GetText(SP_GETWHOLEPHRASE, SP_GETWHOLEPHRASE, TRUE,
                                                            &dstrText, NULL)))
                    {
                        dstrText = wszUnrecognized;
                    }
                    // Concatenate a space onto the end of the recognized word
                    dstrText.Append(L" "); 
     m_edit=dstrText;
     UpdateData(FALSE); 
     
//                   ::SendDlgItemMessage(m_hWnd, IDC_EDIT_DICT, EM_REPLACESEL, TRUE, (LPARAM) W2T(dstrText) );
                   if(!isChineseChar(m_edit))
       {
      
      
         CFindGjlx *m_gjlx=new CFindGjlx();
      m_gjlx->m_ctrlMapX = &(m_ctrlMapX);
      m_gjlx->Create(IDD_GJLX,NULL);
//      m_gjlx->ShowWindow(SW_SHOW);
      m_gjlx->OnSpeech(m_edit);
                        delete m_gjlx;
       }
    }
                break;

        }
    }

BOOL CSpeechDlg::isChineseChar(CString str)
{   
   for(int i=0;i<str.GetLength(); i++)      
   {     
       if(str[i]&0x80)   //字符   
          return TRUE;        
   }  
   return FALSE;
}