⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 demospeech.cpp

📁 包括语音识别和数字TTS 设置语音识别内容的列表
💻 CPP
字号:
// DemoSpeech.cpp : implementation file
//

#include "stdafx.h"
#include "TelMateDemo.h"
#include "DemoSpeech.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CDemoSpeech dialog


CDemoSpeech::CDemoSpeech(CWnd* pParent /*=NULL*/)
	: CDialog(CDemoSpeech::IDD, pParent)
{
	//{{AFX_DATA_INIT(CDemoSpeech)
	m_strName = _T("小王,小张,小明,久久,大哥,爸爸,妈妈,大嫂");
	//}}AFX_DATA_INIT
}


void CDemoSpeech::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CDemoSpeech)
	DDX_Control(pDX, IDC_STOP, m_Stop);
	DDX_Control(pDX, IDC_START, m_Start);
	DDX_Control(pDX, IDC_RESULT, m_cResult);
	DDX_Text(pDX, IDC_NAME, m_strName);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CDemoSpeech, CDialog)
	//{{AFX_MSG_MAP(CDemoSpeech)
	ON_BN_CLICKED(IDC_START, OnStart)
	ON_BN_CLICKED(IDC_STOP, OnStop)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CDemoSpeech message handlers



BOOL CDemoSpeech::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	TV_RegMsgWnd(GetSafeHwnd(),FALSE);//注册接受消息的窗口

	AppendResult("拿起话机,点击'开始识别'后进行语音识别...");
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CDemoSpeech::OnStop() 
{
	TV_StopSpeechDist();
	m_Start.EnableWindow(TRUE);
	m_Stop.EnableWindow(FALSE);
}

void CDemoSpeech::OnStart() 
{
	UpdateData(TRUE);
	if(m_strName.IsEmpty())
	{
		AppendResult("识别内容不能为空");
		return;
	}
	TV_SetSpeechNameList((LPTSTR)(LPCTSTR)m_strName);//设置识别内容列表

	if(!TV_StartSpeechDist(60))//使用默认60的可信度开始识别
	{
		AfxMessageBox("加载语音识别引擎失败,检测目录下是否有Bin\\F_Rom.bin和Bin\\M_Rom.bin");
		return ;
	}

	m_Start.EnableWindow(FALSE);
	m_Stop.EnableWindow(TRUE);
	AppendResult("请说列表中的姓名进行识别...");
}

void CDemoSpeech::AppendResult(char *pBuf)
{
	CString strBuf;
	CTime ct=CTime::GetCurrentTime();
	strBuf.Format("%02d:%02d:%02d %s",ct.GetHour(),ct.GetMinute(),ct.GetSecond(),pBuf);

	CString str;
	m_cResult.GetWindowText(str);
	str=strBuf+"\r\n"+str+"\r\n";
	m_cResult.SetWindowText(str);
}

LRESULT CDemoSpeech::WindowProc(UINT message, WPARAM wParam, LPARAM lParam) 
{
	if(message == TI_GETSPEECH_MESSAGE)
	{
		CString str="识别结果为:";
		str+=(char*)lParam;
		str+="   (其它更接近的结果:";
		str+=TV_GetSpeechResult(1);//第二个结果
		str+="  ";
		str+=TV_GetSpeechResult(2);//第三个结果
		str+=")";
		
		AppendResult((LPTSTR)(LPCTSTR)str);
		AppendResult("请说列表中的姓名继续进行识别...");
	}
	return CDialog::WindowProc(message, wParam, lParam);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -