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

📄 wordrecpdadlg.cpp

📁 The ITU-T(Telecommunication Standardization Sector)is a permanent organ of the International Telecom
💻 CPP
字号:
// WordRecPDADlg.cpp : implementation file
//

#include "stdafx.h"
#include "WordRecPDA.h"
#include "WordRecPDADlg.h"
#include "direct.h"
#include "Utility.h"
#include "..\\CommandEngine.h"

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

/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About

class CAboutDlg : public CDialog
{
public:
	CAboutDlg();

// Dialog Data
	//{{AFX_DATA(CAboutDlg)
	enum { IDD = IDD_ABOUTBOX };
	//}}AFX_DATA

	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CAboutDlg)
	protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
	//}}AFX_VIRTUAL

// Implementation
protected:
	//{{AFX_MSG(CAboutDlg)
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
};

CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
	//{{AFX_DATA_INIT(CAboutDlg)
	//}}AFX_DATA_INIT
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CAboutDlg)
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
	//{{AFX_MSG_MAP(CAboutDlg)
		// No message handlers
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CWordRecPDADlg dialog

CWordRecPDADlg::CWordRecPDADlg(CWnd* pParent /*=NULL*/)
	: CDialog(CWordRecPDADlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CWordRecPDADlg)
	m_strInf = _T("");
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CWordRecPDADlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CWordRecPDADlg)
	DDX_Control(pDX, IDC_LIST_ALL, m_ctrAll);
	DDX_Control(pDX, IDC_PROGRESS_VOLUME, m_ctrVol);
	DDX_Control(pDX, IDC_COMBO_CMD, m_ctrCmd);
	DDX_Control(pDX, IDC_COMBO_AM, m_ctrAM);
	DDX_Control(pDX, IDC_LIST_WORD, m_ctrWrd);
	DDX_Control(pDX, IDC_BUTTON_TEST, m_ctrTest);
	DDX_Control(pDX, IDC_BUTTON_STOP, m_ctrStop);
	DDX_Control(pDX, IDC_BUTTON_START, m_ctrStart);
	DDX_Text(pDX, IDC_EDIT_INF, m_strInf);
	DDV_MaxChars(pDX, m_strInf, 256);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CWordRecPDADlg, CDialog)
	//{{AFX_MSG_MAP(CWordRecPDADlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_BUTTON_START, OnButtonStart)
	ON_BN_CLICKED(IDC_BUTTON_STOP, OnButtonStop)
	ON_BN_CLICKED(IDC_BUTTON_TEST, OnButtonTest)
	ON_CBN_SELCHANGE(IDC_COMBO_AM, OnSelchangeComboAm)
	ON_CBN_SELCHANGE(IDC_COMBO_CMD, OnSelchangeComboCmd)
	ON_LBN_SELCHANGE(IDC_LIST_WORD, OnSelchangeListWord)
	ON_BN_CLICKED(IDC_BUTTON_EDIT, OnButtonEdit)
	ON_LBN_SELCHANGE(IDC_LIST_ALL, OnSelchangeListAll)
	ON_BN_CLICKED(IDC_BUTTON_DEL, OnButtonDel)
	ON_BN_CLICKED(IDC_TEST1, OnTest1)
	ON_WM_TIMER()
	ON_WM_DESTROY()
	//}}AFX_MSG_MAP
	ON_WM_DESTROY()
	ON_MESSAGE(WM_NEWUTTERANCE, OnBeginUtterance)
	ON_MESSAGE(WM_ADDWAVEFRAME, OnAddWaveFrame)
	ON_MESSAGE(WM_ENDUTTERANCE, OnEndUtterance)
	ON_MESSAGE(WM_DRAGONVOICE_FIRM, OnDragonFirm)
	ON_MESSAGE(WM_DRAGONVOICE_GETVOLUME, OnDragonGetVolume)
	//
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CWordRecPDADlg message handlers

BOOL CWordRecPDADlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	// Add "About..." menu item to system menu.

	// IDM_ABOUTBOX must be in the system command range.
	ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
	ASSERT(IDM_ABOUTBOX < 0xF000);

	CMenu* pSysMenu = GetSystemMenu(FALSE);
	if (pSysMenu != NULL)
	{
		CString strAboutMenu;
		strAboutMenu.LoadString(IDS_ABOUTBOX);
		if (!strAboutMenu.IsEmpty())
		{
			pSysMenu->AppendMenu(MF_SEPARATOR);
			pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
		}
	}

	// Set the icon for this dialog.  The framework does this automatically
	//  when the application's main window is not a dialog
	SetIcon(m_hIcon, TRUE);			// Set big icon
	SetIcon(m_hIcon, FALSE);		// Set small icon
	
	// TODO: Add extra initialization here

	ResetLOG();
	m_nTmCount = 0;

	for (int i=0; i < 5; i++){
		m_strResult[i] = new char[MAX_PATH];
		m_strInfo[i] = new char[MAX_PATH];
		m_strResult[i][0] = '\0';
		m_strInfo[i][0] = '\0';
	}
	memset(m_strCurSelWrd, '\0', sizeof(char));
	strcpy(m_strAM, "MALE");
	strcpy(m_strCmd, "CMDST_DEFAULT");
	m_ctrAM.SelectString(-1, _T(m_strAM));
	m_ctrCmd.SelectString(-1, _T(m_strCmd));
	m_ctrVol.SetPos(0);
	char dataPathName[MAX_PATH];
	//strcpy(dataPathName, "D:\\MyProject\\ASR_WORKSPACE\\PC_CmdEngineTest");
	_getcwd(dataPathName, MAX_PATH);

	if (SrInitDragonVoice (dataPathName, m_strAM, GetSafeHwnd()) == 0)
	{
		SrLoadCommandMode("CMDST_DEFAULT");
		SrLoadCommandMode("COMMANDSET_1");
		SrLoadCommandMode("COMMANDSET_2");
		SrSetActiveCommand(m_strCmd);
		DemoAllCmd();
		SrSetParameter(SET_EP_CHECK, 3);
		SrMicOn();
		SrMicOff();
	}
	else
	{
		AfxMessageBox("Initialize Command Engine Failed, Exit");
		exit(1);
	}
	
	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CWordRecPDADlg::OnSysCommand(UINT nID, LPARAM lParam)
{
	if ((nID & 0xFFF0) == IDM_ABOUTBOX)
	{
		CAboutDlg dlgAbout;
		dlgAbout.DoModal();
	}
	else
	{
		CDialog::OnSysCommand(nID, lParam);
	}
}

// If you add a minimize button to your dialog, you will need the code below
//  to draw the icon.  For MFC applications using the document/view model,
//  this is automatically done for you by the framework.

void CWordRecPDADlg::OnPaint() 
{
	if (IsIconic())
	{
		CPaintDC dc(this); // device context for painting

		SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);

		// Center icon in client rectangle
		int cxIcon = GetSystemMetrics(SM_CXICON);
		int cyIcon = GetSystemMetrics(SM_CYICON);
		CRect rect;
		GetClientRect(&rect);
		int x = (rect.Width() - cxIcon + 1) / 2;
		int y = (rect.Height() - cyIcon + 1) / 2;

		// Draw the icon
		dc.DrawIcon(x, y, m_hIcon);
	}
	else
	{
		CDialog::OnPaint();
	}
}

// The system calls this to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR CWordRecPDADlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}

void CWordRecPDADlg::DemoAllCmd()
{
	int nCmd = SrGetAllCmd(NULL);
	char ** strCmd = new char*[nCmd];
	for (int i=0; i < nCmd; i++)
		strCmd[i] = new char[MAX_WORD_LENGTH*2+2];
	nCmd = SrGetAllCmd(strCmd);
	m_ctrAll.ResetContent();
	for (i=0; i < nCmd; i++)
		m_ctrAll.AddString(strCmd[i]);
	for (i=0; i < nCmd; i++)
		delete [] strCmd[i];
	delete [] strCmd;
}

void CWordRecPDADlg::OnButtonStart() 
{
	if (SrMicOn() == 0)
	{
		m_ctrStart.EnableWindow(FALSE);
		m_ctrStop.EnableWindow(TRUE);
	}
	SetTimer(1, 1000, NULL);
}

void CWordRecPDADlg::OnButtonStop() 
{
	SrMicOff();	
}

void CWordRecPDADlg::OnButtonTest() 
{
	SrBatchWavTest();
}

void CWordRecPDADlg::OnDestroy() 
{
	SrExitDragonVoice();
	for (int i=0; i < 5; i++)
	{
		delete [] m_strResult[i];
		delete [] m_strInfo[i];
	}
	CDialog::OnDestroy();
}

void CWordRecPDADlg::OnSelchangeComboAm() 
{
	// TODO: Add your control notification handler code here
//	int nIndex = m_ctrAM.GetCurSel();
//	m_ctrAM.GetLBText(nIndex, m_strAM);
//	if (SrReplaceAcModel(m_strAM) != 0)
//		AfxMessageBox("声学模型切换失败");
}

void CWordRecPDADlg::OnSelchangeComboCmd() 
{
	int nIndex = m_ctrCmd.GetCurSel();
	m_ctrCmd.GetLBText(nIndex, m_strCmd);
	if (SrSetActiveCommand(m_strCmd) != 0)
		AfxMessageBox("命令集切换失败");
	else
		DemoAllCmd();
}

void CWordRecPDADlg::OnSelchangeListWord() 
{
	int nIndex = m_ctrWrd.GetCurSel();
	if (nIndex < 0) return;
	CString csTemp;
	m_ctrWrd.GetText(nIndex, csTemp);
	strcpy(m_strCurSelWrd, csTemp.GetBuffer(MAX_WORD_LENGTH*2));
	csTemp.ReleaseBuffer(MAX_WORD_LENGTH*2);
}

void CWordRecPDADlg::OnSelchangeListAll() 
{
	int nIndex = m_ctrAll.GetCurSel();
	if (nIndex < 0) return;
	CString csTemp;
	m_ctrAll.GetText(nIndex, csTemp);
	strcpy(m_strCurSelWrd, csTemp.GetBuffer(MAX_WORD_LENGTH*2));
	csTemp.ReleaseBuffer(MAX_WORD_LENGTH*2);
}

void CWordRecPDADlg::OnButtonEdit() 
{
	oCardEdit.DoModal();
	if (oCardEdit.m_bUpdateBook)
	{
		char strCommandSetName[MAX_PATH];
		SrGetActiveCommand(strCommandSetName);
		SrLoadCommandMode(strCommandSetName);
	}
	if (oCardEdit.m_bTestBatch)
	{
		char strCommandSetName[] = "PPP";
		SrUnLoadCommandMode(strCommandSetName);
		SrLoadCommandMode(strCommandSetName);
	}
	DemoAllCmd();
	memset(m_strCurSelWrd, '\0', MAX_WORD_LENGTH*2*sizeof(char));
}

void CWordRecPDADlg::OnButtonDel() 
{ 
	if (AfxMessageBox("您确认要删除吗?", MB_ICONEXCLAMATION  || MB_ICONWARNING)
		== IDCANCEL)
		return;
	if (SrConvertInit() == 0)
	{
		if (SrDeleteWord(m_strCurSelWrd) == 0)
			AfxMessageBox("OK");
		else
			AfxMessageBox("Failed");
		SrConvertExit();
		char strCommandSetName[MAX_PATH];
		SrGetActiveCommand(strCommandSetName);
		SrLoadCommandMode(strCommandSetName);
		DemoAllCmd();
		memset(m_strCurSelWrd, '\0', MAX_WORD_LENGTH*2*sizeof(char));	
	}
	else
		AfxMessageBox("Failed");
}

// ==============================================================
// 自定义消息响应函数
LRESULT CWordRecPDADlg::OnBeginUtterance(WPARAM wParam, LPARAM lParam)
{
	return 0L;
}

LRESULT CWordRecPDADlg::OnAddWaveFrame(WPARAM wParam, LPARAM lParam)
{
	return 0L;
}

LRESULT CWordRecPDADlg::OnEndUtterance(WPARAM wParam, LPARAM lParam)
{
	TRACE1("Total Frames is %d\n\n", lParam);

// 调试录音和端点检测线程时
#ifdef	DEBUG_1
	char strResult[260];
	sprintf(strResult, "%d", lParam);
	if (m_ctrWrd.GetCount() >= 5)
		m_ctrWrd.ResetContent();
	m_ctrWrd.AddString(strResult);
	m_ctrStart.EnableWindow(TRUE);
	m_ctrStop.EnableWindow(FALSE);
#endif
	return 0L;
}

LRESULT CWordRecPDADlg::OnDragonFirm(WPARAM wParam, LPARAM lParam)
{
	int i, nWrd = 5;
	SrGetFirmWords(m_strResult, nWrd);
	if (nWrd > 0)
	{
		m_ctrWrd.ResetContent();
		for (i=0; i < nWrd; i++)
			m_ctrWrd.AddString(m_strResult[i]);
	m_ctrStart.EnableWindow(TRUE);
	m_ctrStop.EnableWindow(FALSE);
	//////////////////////////////
	Sleep(200);
	OnButtonStart();
	//////////////////////////////
	}
	return 0L;
}

LRESULT CWordRecPDADlg::OnDragonGetVolume(WPARAM wParam, LPARAM lParam)
{
	int nVol = SrGetAudioVolume();
	nVol *= 4;
	nVol = nVol <= 100 ? nVol : 100;
	m_ctrVol.SetPos(nVol);
	return 0L;
}
// ========================================================================= 

void CWordRecPDADlg::OnTest1() 
{
	CFileDialog oFileDlg(TRUE, "wav", "*.wav");
	if (oFileDlg.DoModal() != IDOK) return;
	CString strFilePath = oFileDlg.GetPathName();
	int  nWrd = 5;
	char * strWrd[260];
	for (int i=0; i < nWrd; i++)
		strWrd[i] = new char[260];

	SrSingleWavTest(strFilePath.GetBuffer(MAX_PATH), strWrd, nWrd);

	strFilePath.ReleaseBuffer();
	while (m_ctrWrd.GetCount() != 0)
		m_ctrWrd.DeleteString(0);
	for (i=0; i < nWrd; i++)
		m_ctrWrd.AddString(strWrd[i]);
	for (i=0; i < 5; i++)
		delete [] strWrd[i];
}

void CWordRecPDADlg::OnTimer(UINT nIDEvent) 
{
	if (nIDEvent == 1)
	{
		//
		m_nTmCount ++;
		if (m_nTmCount == 10)
		{
			m_nTmCount = 0;
			KillTimer(1);
			SrMicOff();

			Sleep(1000);

			OnButtonStart();
		}
	}
	
	CDialog::OnTimer(nIDEvent);
}

⌨️ 快捷键说明

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