#include <windows.h>
#include <sapi.h>
#include <stdio.h>
#include <string.h>
#include <atlbase.h>
#include "sphelper.h"
inline HRESULT BlockForResult(ISpRecoContext * pRecoCtxt, ISpRecoResult ** ppResult)
{
//创建语音识别
HRESULT hr = S_OK;
CSpEvent event;
while (SUCCEEDED(hr) &&
SUCCEEDED(hr = event.GetFrom(pRecoCtxt)) &&
hr == S_FALSE)
{
hr = pRecoCtxt->WaitForNotifyEvent(INFINITE);
}
*ppResult = event.RecoResult();
if (*ppResult)
{
(*ppResult)->AddRef();
}
return hr;
}
const WCHAR * StopWord()
{
const WCHAR * pchStop;
LANGID LangId = ::SpGetUserDefaultUILanguage();
switch (LangId)
{
case MAKELANGID(LANG_JAPANESE, SUBLANG_DEFAULT):
pchStop = L"/x7d42/x4e86///x30b7/x30e5/x30fc/x30ea/x30e7/x30fc//x3057/x3085/x3046/x308a/x3087/x3046";;
break;
default:
pchStop = L"Stop";
break;
}
return pchStop;
}
int _tmain(int argc, TCHAR* argv[])
{
HRESULT hr = E_FAIL;
bool fUseTTS = true; // turn TTS play back on or off
bool fReplay = true; // turn Audio replay on or off
TCHAR szFileName[256];
// Process optional arguments
if (argc > 1)
{
int i;
for (i = 1; i < argc; i++)
{
if (_tcsicmp(argv[i], _T("-noTTS")) == 0)
{
fUseTTS = false;
continue;
}
if (_tcsicmp(argv[i], _T("-noReplay")) == 0)
{
fReplay = false;
continue;
}
if (_tcsicmp(argv[i], _T("-f")) == 0)
{
if( ++i < argc )
{
_tcscpy(szFileName, argv[i]);
continue;
}
}
#ifndef _WIN32_WCE
printf ("Usage: %s [-noTTS] [-noReplay] /n", argv[0]);
#else
RETAILMSG(TRUE,(_T("Usage: %s [-noTTS] [-noReplay] /n"), argv[0]));
#endif
return hr;
}
}
if (SUCCEEDED(hr = :: CoInitializeEx(NULL,COINIT_MULTITHREADED)))
{
{
CComPtr<ISpRecoContext> cpRecoCtxt;
CComPtr<ISpRecoGrammar> cpGrammar;
CComPtr<ISpVoice> cpVoice;
#ifndef _WIN32_WCE
hr = cpRecoCtxt.CoCreateInstance(CLSID_SpSharedRecoContext);
#else
// CLSID_SpInProcRecoContext is only defined when SAPI_AUTOMATION is
// defined, as a result, the following line doesn't work on CE. As a workaround, I
// create an inproc recognizer and get a reco context from that.
//cpRecoCtxt.CoCreateInstance(CLSID_SpInProcRecoContext);
CComPtr<ISpRecognizer> m_cpEngine;
m_cpEngine.CoCreateInstance(CLSID_SpInprocRecognizer);
m_cpEngine->CreateRecoContext( &cpRecoCtxt );
#endif
if(SUCCEEDED(hr))
{
hr = cpRecoCtxt->GetVoice(&cpVoice);
}
if (!cpRecoCtxt || !cpVoice)
{
hr = E_FAIL;
}
if(SUCCEEDED(hr))
{
hr = cpRecoCtxt->SetNotifyWin32Event();
}
if(SUCCEEDED(hr))
{
hr = cpRecoCtxt->SetInterest(SPFEI(SPEI_RECOGNITION), SPFEI(SPEI_RECOGNITION));
}
if(SUCCEEDED(hr))
{
hr = cpRecoCtxt->SetAudioOptions(SPAO_RETAIN_AUDIO, NULL, NULL);
}
if(SUCCEEDED(hr))
{
hr = cpRecoCtxt->CreateGrammar(0, &cpGrammar);
}
//debug
// if(SUCCEEDED(hr))
// {
// hr = cpGrammar->LoadCmdFromFile( szFileName, SPLO_STATIC );
// }
//debug
if(SUCCEEDED(hr))
{
hr = cpGrammar->LoadDictation(NULL, SPLO_STATIC);
}
if(SUCCEEDED(hr))
{
hr = cpGrammar->SetDictationState(SPRS_ACTIVE);
}
if(SUCCEEDED(hr))
{
USES_CONVERSION;
const WCHAR * const pchStop = StopWord();
CComPtr<ISpRecoResult> cpResult;
#ifndef _WIN32_WCE
printf( "I will repeat everything you say./nSay /"%s/" to exit./n", W2A(pchStop) );
#else
RETAILMSG(TRUE,( _T("I will repeat everything you say./nSay /"%s/" to exit./n"), pchStop));
#endif
if (fUseTTS)
{
cpVoice->Speak( L"I will repeat everything you say.", SPF_ASYNC, NULL);
cpVoice->Speak( L"Say stop to exit.", SPF_ASYNC, NULL);
cpVoice->Speak( L"Say <emph> stop </emph> to exit.", SPF_ASYNC | SPF_IS_XML, NULL);
}
while (SUCCEEDED(hr = BlockForResult(cpRecoCtxt, &cpResult)))
{
cpGrammar->SetDictationState( SPRS_INACTIVE );
CSpDynamicString dstrText;
if (SUCCEEDED(cpResult->GetText(SP_GETWHOLEPHRASE, SP_GETWHOLEPHRASE,
TRUE, &dstrText, NULL)))
{
#ifndef _WIN32_WCE
printf("I heard: %s/n", W2A(dstrText));
#else
RETAILMSG(TRUE,( _T("I heard: %s/n"), dstrText));
#endif
if (fUseTTS)
{
cpVoice->Speak( L"I heard", SPF_ASYNC, NULL);
cpVoice->Speak( dstrText, SPF_ASYNC, NULL );
}
if (fReplay)
{
if (fUseTTS)
cpVoice->Speak( L"when you said", SPF_ASYNC, NULL);
else
{
#ifndef _WIN32_WCE
printf ("/twhen you said.../n");
#else
RETAILMSG(TRUE,( _T("/twhen you said.../n")));
#endif
}
cpResult->SpeakAudio(NULL, 0, NULL, NULL);
}
cpResult.Release();
}
if (_wcsicmp(dstrText, pchStop) == 0)
{
break;
}
cpGrammar->SetDictationState( SPRS_ACTIVE );
}
}
}
::CoUninitialize();
}
return hr;
}
需要的留下Email,我给大家发
分享到:
相关推荐
WINCE5.0 VS2005 应用例子供WINCE开发参考。
此程序是在wince平台上运行的日历程序。基于EVC4.0和Wince5.0平台
本原码是基于Wince5.0在S3C2440硬件环境下利用EVC4.0开发的一个多功能通讯录。具有添加,删除,编辑等功能,,还可以读写文件。。
内置25个WinCE5.0程序,包括系统工具,媒体播放、游戏、计算器等 这些的程序都是由通过网络收集的 程序能都在WinCE5.0上完美运行(分别在WinCE5.0模拟器和装有WinCE5.0的导航仪上成功运行)
基于WinCE5.0平台的三星S3C2440的BSP包更新, 最新获取,不敢独享。 希望对大家有所帮助
wince5.0 sdk 配置
本原码是基于Wince5.0在S3C2440硬件环境下利用EVC4.0开发的五子棋游戏源码。。
wince5.0 explorer.exe
本文主要介绍基于WINCE 平台下eVC 进行应用程序开发时会常常用到的一些功能函数\WinCE 下的GPRS 应用
WINCE 5.0 qq软件 QQ软件WINCE版本
祖马是一款wince5.0游戏,还比较好玩
软件中的语音技术包括两方面的内容,一个是语音识别(speech recognition) 和语音合成(speech synthesis)。这两个技术都需要语音引擎的支持。微软推出的应用编程接口API,虽然现在不是业界标准,但是应用比较广泛。
目前权限只能上传45MB大小的文件,只能分包压缩上传了,需要用的请将两个压缩包都下载下来再解压缩。
基于WinCE平台C#编程要点之一 by 英创信息技术有限公司.pdf
为了建立WINCE5.0 的应用开发环境,您需要准备好由微软公司发布的PB (Platform Builder 5.0)安装光盘。这张光盘包含了微软公司的Windows® CE .NET 5.0 操作 系统安装程序,以及把操作系统编译移植到指定目标硬件...
wince5.0模拟器下运行通过,wince5.0自带的媒体播放器,从platform builder下分离出来,用evc4.0编译运行。
Win CE5.0模拟器简体中文版 使用说明: 下载后,先解开压缩包,直接运行里面的.bat文件就可以使用了
基于 WinCE 5.0 的 zenOn HMI 开发
wince5.0 sdk vs2008可用
UDP通信实验.WINCE5.0 UDP通信实验.WINCE5.0 UDP通信实验.WINCE5.0