📄 wcydlg.cpp
字号:
// WCYDlg.cpp : implementation file
//
#include "stdafx.h"
#include "WCY.h"
#include "WCYDlg.h"
#include "itrec.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
HANDLE hMutex;
char config_file[1024];
char uttinfo_file[1024];
CString ASRresultstr_server;
//CString ASRresultstr;
char etalkPath[1024];
int m_List;
//int success_1=0;
SOCKET m_socket;/////socket
num_struct * m_num=new num_struct;
//int m_n;
int m_client;
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()
/////////////////////////////////////////////////////////////////////////////
// CWCYDlg dialog
CWCYDlg::CWCYDlg(CWnd* pParent /*=NULL*/)
: CDialog(CWCYDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CWCYDlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CWCYDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CWCYDlg)
DDX_Control(pDX, IDC_LIST2, m_ListP_i);
DDX_Control(pDX, IDC_LISTCTL, m_ListCtl);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CWCYDlg, CDialog)
//{{AFX_MSG_MAP(CWCYDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_Btn_ASR, OnBtnASR)
//}}AFX_MSG_MAP
ON_MESSAGE(WM_RESLUTDATE,OnResult)
ON_MESSAGE(WM_CONN,OnConn)
ON_MESSAGE(WM_CANCLE,OnCancle)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CWCYDlg message handlers
BOOL CWCYDlg::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
InitSocket();
//flag=0;
//hMutex=CreateMutex(NULL,INFINITE,NULL);
// WaitForSingleObject(hMutex,INFINITE);
//ReleaseMutex(hMutex);
//////////////////////////////////////////////开起服务线程
int returnCode;
char *tmp_ptr = NULL;
char temp[100];
tmp_ptr = getenv(VOICETOUCH_PATH);
if (tmp_ptr == NULL) {
sprintf(temp,"s% %s"," not defined\n", VOICETOUCH_PATH);
}
else
{
strcpy(etalkPath, tmp_ptr);
}
sprintf(config_file, "%s%s", etalkPath, "\\Sample\\Config\\Country.cfg");
sprintf(uttinfo_file, "%s%s", etalkPath, "\\Sample\\Config\\uttinfo.txt");
int instance_started;
returnCode = itrec_initialize(config_file, NUM_INSTANCE, &instance_started);
if (returnCode != VT_EXIT_SUCCESS) {
strcpy(temp, "itrec_init() failed!\r\n");
}
else
sprintf(temp,"itrec_init() succeeded. %d ASR initialized\r\n", instance_started);
ASRresultstr_server+=temp;
///////////////////////////////////////////////////列表视控件
//标题列
LVCOLUMN column;
column.mask=LVCF_FMT|LVCF_WIDTH|LVCF_TEXT|LVCF_SUBITEM;
column.fmt=LVCFMT_LEFT;
column.cx=100;
column.iSubItem=0;
column.pszText="LICENSE";
m_ListCtl.InsertColumn(0,&column);
column.pszText="IP"; //第二个列表视控件
m_ListP_i.InsertColumn(0,&column);
column.iSubItem=1;
column.pszText="SUCCESS";
m_ListCtl.InsertColumn(1,&column);
column.pszText="PORT"; //第二个
m_ListP_i.InsertColumn(1,&column);
//
LVITEM item;
item.mask=LVIF_TEXT|LVIF_IMAGE;
item.iSubItem=0;
item.iItem=0;
item.pszText="lisence 1:";
m_ListCtl.InsertItem(&item);
//item.pszText=" ";//第二个
//m_ListP_i.InsertItem(&item);
item.iItem=1;
item.pszText="lisence 2:";
m_ListCtl.InsertItem(&item);
//item.pszText=" ";//第二个
//m_ListP_i.InsertItem(&item);
item.iItem=2;
item.pszText="lisence 3:";
m_ListCtl.InsertItem(&item);
item.pszText=" ";//第二个
m_ListP_i.InsertItem(&item);
//////////////////////////////////////开服务线程
thread_type* thread_server=new thread_type;
thread_server->hwnd=m_hWnd;
thread_server->S=m_socket;
//int flag=0;
HANDLE hThread=CreateThread(NULL,0,Hhread_Num,(LPVOID)thread_server,0,NULL);
return TRUE; // return TRUE unless you set the focus to a control
}
void CWCYDlg::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 CWCYDlg::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 CWCYDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
int CWCYDlg::ASR(char * str_addr)
{
int returnCode=0;
//instance_started=0;
char *tmp_ptr = NULL;
// unsigned ptr[NUM_INSTANCE];
char temp[100];
// get environment variable
tmp_ptr = getenv(VOICETOUCH_PATH);
if (tmp_ptr == NULL) {
sprintf(temp,"s% %s"," not defined\n", VOICETOUCH_PATH);
return 0;
}
else
{
strcpy(etalkPath, tmp_ptr);
}
// Get config file from command line.
if (read_argument()) {
return 0;
}
// Step 1: Call itrec_init() to initialize VoiceTouch ASR.
// returnCode = itrec_initialize(config_file, NUM_INSTANCE, &instance_started);
if (returnCode != VT_EXIT_SUCCESS) {
strcpy(temp, "itrec_init() failed!");
MessageBox(temp);
return 0;
}
else
//sprintf(temp,"itrec_init() succeeded. %d ASR initialized\r\n", instance_started);
// sprintf(temp,"%s : itrec_init() succeeded. %d ASR initialized\r\n", str_addr,instance_started);
//ASRresultstr=temp;
return 0;
}
int CWCYDlg::read_argument()
{
sprintf(config_file, "%s%s", etalkPath, "\\Sample\\Config\\Country.cfg");
sprintf(uttinfo_file, "%s%s", etalkPath, "\\Sample\\Config\\uttinfo.txt");
return 0;
}
DWORD WINAPI CWCYDlg::entry(LPVOID lpParameter)
{
//WaitForSingleObject(hMutex,INFINITE);
HWND hwnd=((sockrecv*)lpParameter)->hwnd;
int m_index=((sockrecv*)lpParameter)->index;
SOCKET m_socket=((sockrecv*)lpParameter)->S;
char * m_ip=((sockrecv*)lpParameter)->str_ip;
int m_port=((sockrecv*)lpParameter)->str_port;
CString ASRresultstr;
////////////////////////////////////////////////////
UttInfo utt;
FILE *fp = NULL;
char tempname[100];
int doneFlag, numResult, recogStat;
float speechBegin, speechEnd;
VT_GRAMMAR lp_grammar;
VT_RESULT *results = NULL;
int i;
int fail=0;
int success=0;
////////////////////////////////////////////////////////////////////////////////////////////
int returnCode ;
////////////////////////////////////////////////////////////////////////////////////////////
// Open utterance information file for reading.
FILE *ufp = NULL;
if ((ufp = fopen(uttinfo_file, "r")) == NULL)
{
ASRresultstr+="uttinfo_file fail open";
//return 0 ;
}
//::MessageBox(hwnd," ok","警告",MB_OK);
//WaitForSingleObject(hMutex,INFINITE);
//for (;;)
//{
// Read utterance information from file.
if ( fscanf(ufp, "%s %s\n", utt.file, utt.grammar) <= 0 )
{}
// Open the file to be recognized
/*if (fp != NULL)
fclose(fp);
if ((fp = fopen(utt.file, "rb")) == NULL)
{
//continue;
}*/
memset(&lp_grammar, 0, sizeof(VT_GRAMMAR));
strcpy(lp_grammar.szGrammarName, utt.grammar);
// Step 1: Attach to the recognizer
returnCode = itrec_attach_recognizer(m_index);
if (returnCode != VT_EXIT_SUCCESS)
{
ASRresultstr+="itrec_attach_recognizer_fail\r\n";
//continue;
}
else
{
//ASRresultstr+="recognize finished\t";
}
// Step 2: Call itrec_activate_grammar() to activate the grammar
returnCode = itrec_activate_grammar(m_index, &lp_grammar);
if (returnCode != VT_EXIT_SUCCESS)
{
//ASRresultstr+="fail...............\t";
itrec_detach_recognizer(m_index);
//ASRresultstr+="fail";
//continue;
}
// Step 3: Start recognition
returnCode = itrec_start_recognizer(m_index);
if (returnCode != VT_EXIT_SUCCESS)
{
itrec_detach_recognizer(m_index);
}
// Step 4 & 5: Send speech data to ASR
// Keep on sending speech data to ASR until there is a result or
// there is no more speech data.
//ASRresultstr+="Recognition in progress";
numResult = 0;
doneFlag = 0;
/////////////////////////////////////////////////////////////////////////////////////////////
// FILE* stream;
struct Fileinfo fileinfo;
int nRet = 0;
unsigned long dataLength, cbLeftToReceive;
BYTE* recdData = NULL;
memset( &fileinfo, 0x00, sizeof(fileinfo) );
nRet = recv( m_socket , ( char *)&fileinfo, sizeof(fileinfo), 0 );
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -