- Visual C++源码
- Visual Basic源码
- C++ Builder源码
- Java源码
- Delphi源码
- C/C++源码
- PHP源码
- Perl源码
- Python源码
- Asm源码
- Pascal源码
- Borland C++源码
- Others源码
- SQL源码
- VBScript源码
- JavaScript源码
- ASP/ASPX源码
- C#源码
- Flash/ActionScript源码
- matlab源码
- PowerBuilder源码
- LabView源码
- Flex源码
- MathCAD源码
- VBA源码
- IDL源码
- Lisp/Scheme源码
- VHDL源码
- Objective-C源码
- Fortran源码
- tcl/tk源码
- QT源码
CardDlg.cpp
资源名称:语音程序.rar [点击查看]
上传用户:lczygg
上传日期:2007-07-03
资源大小:2947k
文件大小:5k
源码类别:
语音合成与识别
开发平台:
Visual C++
- // CardDlg.cpp : implementation file
- //
- #include "stdafx.h"
- #include "WordRecPDA.h"
- #include "CardDlg.h"
- #include "..\CommandEngine.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CCardDlg dialog
- CCardDlg::CCardDlg(CWnd* pParent /*=NULL*/)
- : CDialog(CCardDlg::IDD, pParent)
- {
- //{{AFX_DATA_INIT(CCardDlg)
- m_strName = _T("");
- m_bUpdateBook = FALSE;
- m_bTestBatch = FALSE;
- m_strPinyin = _T("");
- //}}AFX_DATA_INIT
- }
- void CCardDlg::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CCardDlg)
- DDX_Text(pDX, IDC_EDIT_NAME, m_strName);
- DDV_MaxChars(pDX, m_strName, 11);
- DDX_Text(pDX, IDC_EDIT_INFO, m_strPinyin);
- //}}AFX_DATA_MAP
- }
- BEGIN_MESSAGE_MAP(CCardDlg, CDialog)
- //{{AFX_MSG_MAP(CCardDlg)
- ON_BN_CLICKED(IDC_BUTTON_ADD, OnButtonAdd)
- ON_BN_CLICKED(IDC_BUTTON_DELETE, OnButtonDelete)
- ON_BN_CLICKED(IDC_BUTTON_BATCH, OnButtonBatch)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CCardDlg message handlers
- void CCardDlg::OnButtonAdd()
- {
- CString strMsg;
- UpdateData(TRUE);
- char strName[MAX_PATH], strPiny[MAX_PATH];
- strcpy(strName, m_strName);
- strcpy(strPiny, m_strPinyin);
- if (strlen(strName) == 0) return;
- else if (strlen(strName) > MAX_WORD_LENGTH*2){
- strMsg.Format("名字不能超过%d个字!", MAX_WORD_LENGTH);
- AfxMessageBox(strMsg);
- return;
- }
- for (unsigned int i=0; i < strlen(strName); i++){
- if (strName[i] >= 0){
- AfxMessageBox("请输入中文字符!", MB_OK, 0);
- return;
- }
- }
- //自动注音
- //if (SrAddWord(strName, NULL) == 0) {
- // AfxMessageBox("OK");
- // m_bUpdateBook = true;
- //}
- //else
- // AfxMessageBox("Failed");
- //半自动注音
- char* strPinyin[MAX_WORD_LENGTH];
- for (i=0; i < MAX_WORD_LENGTH; i++) {
- strPinyin[i] = new char[7];
- strcpy(strPinyin[i], "");
- }
- if (strcmp(strPiny, "") == 0) {
- if (SrAddWord(strName, strPinyin) == 0) {
- m_strPinyin = "";
- for (i=0; i < strlen(strName)/2; i++) {
- m_strPinyin += strPinyin[i];
- m_strPinyin += " ";
- }
- UpdateData(FALSE);
- }
- }
- else {
- strcpy(strPiny, m_strPinyin);
- i = 0;
- char * pStr = strtok(strPiny, " tn");
- while (pStr != NULL && i < MAX_WORD_LENGTH)
- {
- if (strlen(pStr) <= 7)
- strcpy(strPinyin[i], pStr);
- else
- strcpy(strPinyin[i], " ");
- pStr = strtok(NULL, " tn");
- i++;
- }
- if (SrAddWord(strName, strPinyin) == 0) {
- AfxMessageBox("已加入!");
- m_bUpdateBook = TRUE;
- }
- else
- AfxMessageBox("加词失败!");
- m_strName = "";
- m_strPinyin = "";
- UpdateData(FALSE);
- }
- for (i=0; i < MAX_WORD_LENGTH; i++)
- delete [] strPinyin[i];
- }
- void CCardDlg::OnButtonDelete()
- {
- char strMsg[MAX_PATH];
- UpdateData();
- char* strName = m_strName.GetBuffer(20);
- if( strlen(strName) == 0 )
- return;
- else if( strlen(strName) > MAX_WORD_LENGTH*2)
- {
- sprintf(strMsg, "名字不能超过%d个字!", MAX_WORD_LENGTH);
- AfxMessageBox( strMsg );
- return;
- }
- char csMessage[30];
- sprintf(csMessage, "您确认要删除吗?");
- if( AfxMessageBox(csMessage, MB_ICONEXCLAMATION || MB_ICONWARNING )
- == IDOK ){
- if (SrDeleteWord(strName) == 0)
- AfxMessageBox("OK");
- else
- AfxMessageBox("Failed");
- m_bUpdateBook = true;
- }
- m_strName.ReleaseBuffer(20);
- }
- int CCardDlg::DoModal()
- {
- m_bUpdateBook = FALSE;
- SrConvertInit();
- int ret = CDialog::DoModal();
- SrConvertExit();
- return ret;
- }
- void CCardDlg::OnButtonBatch()
- {
- char strSourceFile[MAX_PATH], strMsg[MAX_PATH];
- char strCommandSetName[] = "CMDST_COMMAND";
- CFileDialog oFileDlg(TRUE, "txt", "*.txt");
- if (oFileDlg.DoModal() != IDOK) return;
- CString str = oFileDlg.GetPathName();
- strcpy(strSourceFile, str.GetBuffer(MAX_PATH));
- int ret = SrNewCommandSet(strSourceFile, strCommandSetName);
- if (ret == 0) {
- sprintf(strMsg, "New %s has been generated!", strCommandSetName);
- AfxMessageBox(strMsg);
- }
- m_bTestBatch = true;
- /* FILE * fp = fopen(strSourceFile, "rt");
- if (fp)
- {
- char strTmp[260];
- fgets(strTmp, 260, fp);
- int nWrd = atoi(strTmp);
- char ** strWrds = new char*[nWrd];
- char ** strPinyin = new char*[nWrd];
- for (int i=0; i < nWrd; i++)
- {
- strWrds[i] = new char[MAX_WORD_LENGTH*2+1];
- fgets(strTmp, 260, fp);
- strcpy(strWrds[i], strtok(strTmp, " tn"));
- char * pStr;
- pStr = strtok(NULL, "n");
- if (pStr == NULL)
- strPinyin[i] = NULL;
- else
- {
- strPinyin[i] = new char[(MAX_WORD_LENGTH+1)*7];
- strcpy(strPinyin[i], pStr);
- }
- }
- int * pWrongIdx = new int[nWrd];
- //int ret = SrGenerateLextree(strWrds, nWrd, strCommandSetName);
- int ret = SrGenerateLextree(strWrds, nWrd, strCommandSetName, strPinyin, pWrongIdx);
- if (ret == 0) {
- sprintf(strMsg, "New %s has been generated!", strCommandSetName);
- AfxMessageBox(strMsg);
- }
- delete [] pWrongIdx;
- for (i=0; i < nWrd; i++)
- delete [] strPinyin[i];
- delete [] strPinyin;
- for (i=0; i < nWrd; i++)
- delete [] strWrds[i];
- delete [] strWrds;
- }
- fclose(fp);
- */
- }