www.pudn.com > HMRspeech.rar > ListenDlg.cpp, change:2009-11-04,size:2897b


// ListenDlg.cpp : implementation file 
// 
 
#include "stdafx.h" 
#include "speech.h" 
#include "ListenDlg.h" 
 
#ifdef _DEBUG 
#define new DEBUG_NEW 
#undef THIS_FILE 
static char THIS_FILE[] = __FILE__; 
#endif 
 
///////////////////////////////////////////////////////////////////////////// 
// CListenDlg dialog 
 
 
CListenDlg::CListenDlg(CWnd* pParent /*=NULL*/) 
	: CDialog(CListenDlg::IDD, pParent) 
{ 
	//{{AFX_DATA_INIT(CListenDlg) 
	m_strText = _T(""); 
	//}}AFX_DATA_INIT 
} 
 
 
void CListenDlg::DoDataExchange(CDataExchange* pDX) 
{ 
	CDialog::DoDataExchange(pDX); 
	//{{AFX_DATA_MAP(CListenDlg) 
	DDX_Control(pDX, IDC_BUTTON5, m_btDictation); 
	DDX_Text(pDX, IDC_LISTEN_EDIT, m_strText); 
	//}}AFX_DATA_MAP 
} 
 
 
BEGIN_MESSAGE_MAP(CListenDlg, CDialog) 
	//{{AFX_MSG_MAP(CListenDlg) 
	ON_BN_CLICKED(IDC_BUTTON5, OnButtonListen) 
	ON_BN_CLICKED(IDC_BUTTON6, OnButtonVt) 
	ON_BN_CLICKED(IDC_BUTTON7, OnButtonMs) 
	ON_WM_DESTROY() 
	ON_WM_CLOSE() 
	//}}AFX_MSG_MAP 
	ON_MESSAGE(WM_SREVENT, OnSREvent) 
END_MESSAGE_MAP() 
 
///////////////////////////////////////////////////////////////////////////// 
// CListenDlg message handlers 
 
// init dialog 
BOOL CListenDlg::OnInitDialog()  
{ 
	CDialog::OnInitDialog(); 
	 
	// TODO: Add extra initialization here 
	 
	if (! m_SpeechRecognition.Initialize(m_hWnd)) 
		AfxMessageBox(m_SpeechRecognition.GetErrorString()); 
 
	m_SpeechRecognition.InitTokenList(GetDlgItem(IDC_LISTEN_VOICE_LIST)->m_hWnd); 
	m_SpeechRecognition.Stop(); 
 
	return TRUE;  // return TRUE unless you set the focus to a control 
	// EXCEPTION: OCX Property Pages should return FALSE 
} 
 
// 开始/停止听写 
void CListenDlg::OnButtonListen()  
{ 
	// TODO: Add your control notification handler code here 
	if (m_SpeechRecognition.IsDictationOn()) 
	{ 
		m_SpeechRecognition.Stop(); 
		m_btDictation.SetWindowText("听写"); 
		SetWindowText("Listener - 请按<听写>按钮开始听写!"); 
	} 
	else 
	{ 
		m_SpeechRecognition.Start(); 
		m_btDictation.SetWindowText("停止"); 
		SetWindowText("Listener - 正在记录,请口述..."); 
	} 
} 
 
// 语音训练 
void CListenDlg::OnButtonVt()  
{ 
	// TODO: Add your control notification handler code here 
	m_SpeechRecognition.VoiceTraining(m_hWnd); 
} 
 
// 话筒设置 
void CListenDlg::OnButtonMs()  
{ 
	// TODO: Add your control notification handler code here 
	m_SpeechRecognition.MicrophoneSetup(m_hWnd); 
} 
 
// 响应消息WM_SREVENT 
LRESULT CListenDlg::OnSREvent(WPARAM wParam, LPARAM lParam) 
{ 
	WCHAR *pwzText; 
	m_SpeechRecognition.GetText(&pwzText); 
	m_strText += CString(pwzText); 
	UpdateData(FALSE); 
	return 0L; 
} 
 
void CListenDlg::OnDestroy()  
{ 
	CDialog::OnDestroy(); 
	 
	// TODO: Add your message handler code here 
	delete this; 
	//AfxMessageBox("destroy"); 
} 
 
void CListenDlg::OnClose()  
{ 
	// TODO: Add your message handler code here and/or call default 
 
	CDialog::OnClose(); 
	DestroyWindow(); 
}