sumom****@users*****
sumom****@users*****
2009年 10月 22日 (木) 01:47:20 JST
Index: julius4/msvc/SampleApp/Julius.cpp diff -u /dev/null julius4/msvc/SampleApp/Julius.cpp:1.1 --- /dev/null Thu Oct 22 01:47:20 2009 +++ julius4/msvc/SampleApp/Julius.cpp Thu Oct 22 01:47:20 2009 @@ -0,0 +1,560 @@ +#include <julius/juliuslib.h> +#include "Julius.h" + +///// R[obNÖ +#define JCALLBACK(A, B) \ +static void A ( Recog *recog, void *data) \ +{\ + cJulius *j = (cJulius *) data;\ + SendMessage(j->getWindow(), WM_JULIUS, B, 0L);\ +} + +JCALLBACK(callback_engine_active, JEVENT_ENGINE_ACTIVE); +JCALLBACK(callback_engine_inactive, JEVENT_ENGINE_INACTIVE); +JCALLBACK(callback_audio_ready, JEVENT_AUDIO_READY); +JCALLBACK(callback_audio_begin, JEVENT_AUDIO_BEGIN); +JCALLBACK(callback_audio_end, JEVENT_AUDIO_END); +JCALLBACK(callback_recog_begin, JEVENT_RECOG_BEGIN); +JCALLBACK(callback_recog_end, JEVENT_RECOG_END); +JCALLBACK(callback_recog_frame, JEVENT_RECOG_FRAME); +JCALLBACK(callback_engine_pause, JEVENT_ENGINE_PAUSE); +JCALLBACK(callback_engine_resume, JEVENT_ENGINE_RESUME); + +static void callback_result_final(Recog *recog, void *data) +{ + cJulius *j = (cJulius *)data; + + int i; + WORD_INFO *winfo; + WORD_ID *seq; + int seqnum; + Sentence *s; + RecogProcess *r; + static char str[2048]; + static wchar_t wstr[2048]; + size_t size = 0; + WPARAM wparam = 0; + + r = j->getRecog()->process_list; + if (! r->live) return; + if (r->result.status < 0) { /* no results obtained */ + switch(r->result.status) { + case J_RESULT_STATUS_REJECT_POWER: + strcpy(str, "<input rejected by power>"); + break; + case J_RESULT_STATUS_TERMINATE: + strcpy(str, "<input teminated by request>"); + break; + case J_RESULT_STATUS_ONLY_SILENCE: + strcpy(str, "<input rejected by decoder (silence input result)>"); + break; + case J_RESULT_STATUS_REJECT_GMM: + strcpy(str, "<input rejected by GMM>"); + break; + case J_RESULT_STATUS_REJECT_SHORT: + strcpy(str, "<input rejected by short input>"); + break; + case J_RESULT_STATUS_FAIL: + strcpy(str, "<search failed>"); + break; + } + return; + } + + winfo = r->lm->winfo; + s = &(r->result.sent[0]); + seq = s->word; + seqnum = s->word_num; + str[0] = '\0'; + for(i=0;i<seqnum;i++) strcat(str, winfo->woutput[seq[i]]); + + mbstowcs_s( &size, wstr, str, strlen(str)+1); + + wparam = (r->result.status << 16) + JEVENT_RESULT_FINAL; + + SendMessage(j->getWindow(), WM_JULIUS, wparam, (LPARAM)wstr); +} + +// |[Ypâ~Ö + +static void callback_wait_for_resume(Recog *recog, void *data) +{ + cJulius *j = (cJulius *)data; + // ±ÌXbhiF¯XbhjÌÀsðf + SuspendThread( j->getThreadHandle() ); + // ÊXbh©çResumeThread()ªÄÎêéÜÅÒ@ +} + +//----------------------------------------------------------------------------------------- + +#ifdef APP_ADIN +static int callback_adin_fetch_input(SP16 *sampleBuffer, int reqlen) +{ + // ¤Lobt@ÉV½È«Ýª é©A é¢ÍOñÌcèª é©`FbN + // êλêðÅå reqlen ¾¯ sampleBuffer É«Þ +} +#endif + +//----------------------------------------------------------------------------------------- + +// F¯XbhÌCÖ +DWORD WINAPI recogThreadMain(LPVOID vdParam) +{ + int ret; + Recog *recog = (Recog *)vdParam; + ret = j_recognize_stream(recog); + if (ret == -1) ExitThread(FALSE); + ExitThread(TRUE); +} + +//----------------------------------------------------------------------------------------- +//----------------------------------------------------------------------------------------- + + +//================ +// RXgN^ +//================ +cJulius::cJulius( void ) : m_jconf( NULL ), m_recog( NULL ), m_opened( false ), m_threadHandle( NULL ), m_fpLogFile( NULL ) +{ +#ifdef APP_ADIN + m_appsource = 0; +#endif + setLogFile( "juliuslog.txt" ); +} + +//============== +// fXgN^ +//============== +cJulius::~cJulius( void ) +{ + release(); + if ( m_fpLogFile ) { + fclose(m_fpLogFile); + m_fpLogFile = NULL; + } +} + +//========= +// ú»1 +//========= +bool cJulius::initialize( int argnum, char *argarray[]) +{ + bool ret; + + release(); + + m_jconf = j_config_load_args_new( argnum, argarray ); + + if (m_jconf == NULL) { /* error */ + return false; + } + + ret = createEngine(); + + return ret; +} + +//========= +// ú»2 +//========= +bool cJulius::initialize( char *filename ) +{ + bool ret; + + release(); + + if (! loadJconf( filename )) return false; + + ret = createEngine(); + + return ret; +} + +//========= +// ú»2 +//========= +bool cJulius::loadJconf( char *filename ) +{ + if (m_jconf) { + if (j_config_load_file(m_jconf, filename) == -1) { + return false; + } + } else { + m_jconf = j_config_load_file_new( filename ); + if (m_jconf == NULL) { /* error */ + return false; + } + } + return true; +} + +//================== +// Ot@CoÍ +//================== +void cJulius::setLogFile( const char *filename ) +{ + if (m_fpLogFile) { + fclose( m_fpLogFile ); + } + m_fpLogFile = fopen( filename, "w" ); + if (m_fpLogFile) { + jlog_set_output( m_fpLogFile ); + } +} + +//================ +// GWú» +//================ +bool cJulius::createEngine( void ) +{ +#ifdef APP_ADIN + ADIn *a; +#endif + + if (!m_jconf) return false; + if (m_recog) return false; + +#ifdef APP_ADIN + if (m_appsource != 0) { + // Av©gÌüÍ̽ßÉjconfÝèðÏX + switch(m_appsource) { + case 1: // buffer input, batch + m_recog->jconf->input.type = INPUT_WAVEFORM; + m_recog->jconf->input.speech_input = SP_RAWFILE; + m_recog->jconf->decodeopt.realtime_flag = FALSE; + break; + case 2: // buffer input, incremental + m_recog->jconf->input.type = INPUT_WAVEFORM; + m_recog->jconf->input.speech_input = SP_RAWFILE; + m_recog->jconf->decodeopt.realtime_flag = TRUE; + break; + } + } +#endif + + // GWðN® + m_recog = j_create_instance_from_jconf(m_jconf); + if (m_recog == NULL) { + return false; + } + + // R[obNðo^ + callback_add(m_recog, CALLBACK_EVENT_PROCESS_ONLINE, ::callback_engine_active, this); + callback_add(m_recog, CALLBACK_EVENT_PROCESS_OFFLINE, ::callback_engine_inactive, this); + callback_add(m_recog, CALLBACK_EVENT_SPEECH_READY, ::callback_audio_ready, this); + callback_add(m_recog, CALLBACK_EVENT_SPEECH_START, ::callback_audio_begin, this); + callback_add(m_recog, CALLBACK_EVENT_SPEECH_STOP, ::callback_audio_end, this); + callback_add(m_recog, CALLBACK_EVENT_RECOGNITION_BEGIN, ::callback_recog_begin, this); + callback_add(m_recog, CALLBACK_EVENT_RECOGNITION_END, ::callback_recog_end, this); + callback_add(m_recog, CALLBACK_EVENT_PASS1_FRAME, ::callback_recog_frame, this); + callback_add(m_recog, CALLBACK_EVENT_PAUSE, ::callback_engine_pause, this); + callback_add(m_recog, CALLBACK_EVENT_RESUME, ::callback_engine_resume, this); + callback_add(m_recog, CALLBACK_RESULT, ::callback_result_final, this); + callback_add(m_recog, CALLBACK_PAUSE_FUNCTION, ::callback_wait_for_resume, this); + +#ifdef APP_ADIN + // ¹ºüÍfoCXðú» + if (m_appsource != 0) { + // AvüÍpÉ©OÅú» + a = m_recog->adin; + switch(m_appsource) { + case 1: // buffer input, batch + a->ad_standby = NULL; + a->ad_begin = NULL; + a->ad_end = NULL; + a->ad_resume = NULL; + a->ad_pause = NULL; + a->ad_terminate = NULL; + a->ad_read = callback_adin_fetch_input; + a->ad_input_name = NULL; + a->silence_cut_default = FALSE; + a->enable_thread = FALSE; + break; + case 2: // buffer input, incremental + a->ad_standby = NULL; + a->ad_begin = NULL; + a->ad_end = NULL; + a->ad_resume = NULL; + a->ad_pause = NULL; + a->ad_terminate = NULL; + a->ad_read = callback_adin_fetch_input; + a->ad_input_name = NULL; + a->silence_cut_default = FALSE; + a->enable_thread = FALSE; + break; + } + a->ds = NULL; + a->down_sample = FALSE; + if (adin_standby(a, m_recog->jconf->input.sfreq, NULL) == FALSE) return false; + if (adin_setup_param(a, m_recog->jconf) == FALSE) return false; + a->input_side_segment = FALSE; + } else { + // JuliusLib Éú»ðC¹é + if (! j_adin_init( m_recog ) ) return false; + } +#else + if (! j_adin_init( m_recog ) ) return false; +#endif + + return true; +} + +//==================== +// ðJn·é +//==================== +bool cJulius::startProcess( HWND hWnd ) +{ + + if ( ! m_recog ) return false; + + // bZ[WMæðÛ¶ + m_hWnd = hWnd; + + if (m_opened == false) { + // foCXðJ + switch(j_open_stream(m_recog, NULL)) { + case 0: /* succeeded */ + break; + case -1: /* error */ + // fprintf(stderr, "error in input stream\n"); + return false; + case -2: /* end of recognition process */ + //fprintf(stderr, "failed to begin input stream\n"); + return false; + } + // XbhðJ + m_threadHandle = CreateThread(NULL, 0, ::recogThreadMain, (LPVOID)m_recog, 0, &m_threadId); + if (m_threadHandle == NULL) { + j_close_stream(m_recog); + return false; + } + SetThreadPriority(m_threadHandle, THREAD_PRIORITY_HIGHEST); + + m_opened = true; + } + + return true; +} + +//================ +// ðI¹·é +//================ +void cJulius::stopProcess( void ) +{ + if (m_opened) { + // Xg[ð¶éiXbhÍI¹·é͸j + j_close_stream(m_recog); + m_opened = false; + } +} + +//========== +// êâ~ +//========== +void cJulius::pause( void ) +{ + // â~ðv + // ~ÜÁ½çAF¯XbhÍ pause Cxgøã PAUSE_FUNCTION R[obNðÀs + j_request_terminate(m_recog); +} + +//========== +// ®ìÄJ +//========== +void cJulius::resume( void ) +{ + // ÄJvðæÉZbg + j_request_resume(m_recog); + // F¯XbhÌ®ìðÄJBF¯XbhÍ resume CxgøãF¯ðÄJ·é + ResumeThread( m_threadHandle ); +} + +//============== +// ¶@ÇÝÝ +//============== +bool cJulius::loadGrammar( WORD_INFO *winfo, DFA_INFO *dfa, char *dictfile, char *dfafile, RecogProcess *r ) +{ + boolean ret; + + // load grammar + switch( r->lmvar ) { + case LM_DFA_WORD: + ret = init_wordlist(winfo, dictfile, r->lm->am->hmminfo, + r->lm->config->wordrecog_head_silence_model_name, + r->lm->config->wordrecog_tail_silence_model_name, + (r->lm->config->wordrecog_silence_context_name[0] == '\0') ? NULL : r->lm->config->wordrecog_silence_context_name, + r->lm->config->forcedict_flag); + if (ret == FALSE) { + return false; + } + break; + case LM_DFA_GRAMMAR: + ret = init_voca(winfo, dictfile, r->lm->am->hmminfo, FALSE, r->lm->config->forcedict_flag); + if (ret == FALSE) { + return false; + } + ret = init_dfa(dfa, dfafile); + if (ret == FALSE) { + return false; + } + break; + } + + return true; +} + +//============== +// ¶@ÇÁ +//============== +bool cJulius::addGrammar( char *name, char *dictfile, char *dfafile, bool deleteAll ) +{ + WORD_INFO *winfo; + DFA_INFO *dfa; + RecogProcess *r = m_recog->process_list; + boolean ret; + + // load grammar + switch( r->lmvar ) { + case LM_DFA_WORD: + winfo = word_info_new(); + dfa = NULL; + ret = loadGrammar( winfo, NULL, dictfile, NULL, r ); + if ( ! ret ) { + word_info_free(winfo); + return false; + } + break; + case LM_DFA_GRAMMAR: + winfo = word_info_new(); + dfa = dfa_info_new(); + ret = loadGrammar( winfo, dfa, dictfile, dfafile, r ); + if ( ! ret ) { + word_info_free(winfo); + dfa_info_free(dfa); + return false; + } + } + if ( deleteAll ) { + /* delete all existing grammars */ + multigram_delete_all(r->lm); + } + /* register the new grammar to multi-gram tree */ + multigram_add(dfa, winfo, name, r->lm); + /* need to rebuild the global lexicon */ + /* tell engine to update at requested timing */ + schedule_grammar_update(m_recog); + /* make sure this process will be activated */ + r->active = 1; + + SendMessage(getWindow(), WM_JULIUS, JEVENT_GRAM_UPDATE, 0L); + + return true; +} + +//============== +// ¶@üêÖ¦ +//============== +bool cJulius::changeGrammar( char *name, char *dictfile, char *dfafile ) +{ + return addGrammar(name, dictfile, dfafile, true); +} + +//============== +// ¶@í +//============== +bool cJulius::deleteGrammar( char *name ) +{ + RecogProcess *r = m_recog->process_list; + int gid; + + gid = multigram_get_id_by_name(r->lm, name); + if (gid == -1) return false; + + if (multigram_delete(gid, r->lm) == FALSE) { /* deletion marking failed */ + return false; + } + /* need to rebuild the global lexicon */ + /* tell engine to update at requested timing */ + schedule_grammar_update(m_recog); + + SendMessage(getWindow(), WM_JULIUS, JEVENT_GRAM_UPDATE, 0L); + + return true; +} + +//============== +// ¶@ê³ø +//============== +bool cJulius::deactivateGrammar( char *name ) +{ + RecogProcess *r = m_recog->process_list; + int gid; + int ret; + + gid = multigram_get_id_by_name(r->lm, name); + if (gid == -1) return false; + + ret = multigram_deactivate(gid, r->lm); + if (ret == 1) { + /* already active */ + return true; + } else if (ret == -1) { + /* not found */ + return false; + } + /* tell engine to update at requested timing */ + schedule_grammar_update(m_recog); + SendMessage(getWindow(), WM_JULIUS, JEVENT_GRAM_UPDATE, 0L); + + return true; +} +//==================== +// ¶@ê³øðð +//==================== +bool cJulius::activateGrammar( char *name ) +{ + RecogProcess *r = m_recog->process_list; + int gid; + int ret; + + gid = multigram_get_id_by_name(r->lm, name); + if (gid == -1) return false; + + ret = multigram_activate(gid, r->lm); + if (ret == 1) { + /* already active */ + return true; + } else if (ret == -1) { + /* not found */ + return false; + } + /* tell engine to update at requested timing */ + schedule_grammar_update(m_recog); + SendMessage(getWindow(), WM_JULIUS, JEVENT_GRAM_UPDATE, 0L); + + return true; +} + +//========= +// ðú +//========= +void cJulius::release( void ) +{ + stopProcess(); + + if (m_threadHandle) { + CloseHandle(m_threadHandle); + m_threadHandle = NULL; + } else { + if ( m_recog ) { + j_recog_free( m_recog ); // jconf will be released inside this + m_recog = NULL; + m_jconf = NULL; + } + if ( m_jconf ) { + j_jconf_free( m_jconf ); + m_jconf = NULL; + } + } + +} \ No newline at end of file Index: julius4/msvc/SampleApp/Julius.h diff -u /dev/null julius4/msvc/SampleApp/Julius.h:1.1 --- /dev/null Thu Oct 22 01:47:20 2009 +++ julius4/msvc/SampleApp/Julius.h Thu Oct 22 01:47:20 2009 @@ -0,0 +1,86 @@ +// +// EJulius ú»F[hµÄȺÌÖðR[obNÉdÞ +// @F¯Jn +// @gKm +//@@Êæ¾ +// eÖÍηébZ[WðEBhEYCxgÖ issue ·é +// E¹ºF¯Jn +// E¹ºF¯fEÄJ +// E¹ºF¯I¹ + +#ifndef _JULIUSCLASS_H_ +#define _JULIUSCLASS_H_ + +#include "julius/juliuslib.h" + +// Jpè` +#undef APP_ADIN + +// [Uè`Cxg +#define WM_JULIUS (WM_USER + 1) + +// CxgID +enum { + JEVENT_ENGINE_ACTIVE, + JEVENT_ENGINE_INACTIVE, + JEVENT_ENGINE_PAUSE, + JEVENT_ENGINE_RESUME, + JEVENT_AUDIO_READY, + JEVENT_AUDIO_BEGIN, + JEVENT_AUDIO_END, + JEVENT_RECOG_BEGIN, + JEVENT_RECOG_END, + JEVENT_RECOG_FRAME, + JEVENT_RESULT_FRAME, + JEVENT_RESULT_PASS1, + JEVENT_RESULT_FINAL, + JEVENT_GRAM_UPDATE, +}; + + +class cJulius +{ + private : + Jconf *m_jconf; // Configuration parameter data + Recog *m_recog; // Engine instance + bool m_opened; + FILE *m_fpLogFile; + HANDLE m_threadHandle; + DWORD m_threadId; + HWND m_hWnd; +#ifdef APP_ADIN + int m_appsource +#endif + + public : + cJulius( void ); + ~cJulius( void ); + + void setLogFile( const char *filename ); + + bool initialize( int argnum, char *argarray[] ); + bool initialize( char *jconffile ); + bool loadJconf( char *jconffile ); + bool createEngine( void ); + + bool startProcess( HWND hWnd ); + void stopProcess( void ); + + void pause( void ); + void resume( void ); + + bool loadGrammar( WORD_INFO *winfo, DFA_INFO *dfa, char *dictfile, char *dfafile, RecogProcess *r ); + bool addGrammar( char *name, char *dictfile, char *dfafile, bool deleteAll = false ); + bool changeGrammar( char *name, char *dictfile, char *dfafile ); + bool deleteGrammar( char *name ); + bool deactivateGrammar( char *name ); + bool activateGrammar( char *name ); + + inline HWND getWindow( void ) { return m_hWnd; }; + inline Recog *getRecog( void ) { return m_recog; }; + inline HANDLE getThreadHandle( void ) { return m_threadHandle; }; + + void release( void ); +}; + +#endif Index: julius4/msvc/SampleApp/Resource.h diff -u /dev/null julius4/msvc/SampleApp/Resource.h:1.1 --- /dev/null Thu Oct 22 01:47:20 2009 +++ julius4/msvc/SampleApp/Resource.h Thu Oct 22 01:47:20 2009 @@ -0,0 +1,35 @@ +//{{NO_DEPENDENCIES}} +// Microsoft Visual C++ generated include file. +// Used by SampleApp.rc +// + +#define IDS_APP_TITLE 103 + +#define IDR_MAINFRAME 128 +#define IDD_SAMPLEAPP_DIALOG 102 +#define IDD_ABOUTBOX 103 +#define IDM_ABOUT 104 +#define IDM_EXIT 105 +#define IDI_SAMPLEAPP 107 +#define IDI_SMALL 108 +#define IDC_SAMPLEAPP 109 +#define IDC_MYICON 2 +#ifndef IDC_STATIC +#define IDC_STATIC -1 +#endif + +#define IDM_PAUSE 32771 +#define IDM_RESUME 32772 + +// Vµ¢IuWFNgÌÌùèl +// +#ifdef APSTUDIO_INVOKED +#ifndef APSTUDIO_READONLY_SYMBOLS + +#define _APS_NO_MFC 130 +#define _APS_NEXT_RESOURCE_VALUE 129 +#define _APS_NEXT_COMMAND_VALUE 32773 +#define _APS_NEXT_CONTROL_VALUE 1000 +#define _APS_NEXT_SYMED_VALUE 110 +#endif +#endif Index: julius4/msvc/SampleApp/SampleApp.cpp diff -u /dev/null julius4/msvc/SampleApp/SampleApp.cpp:1.1 --- /dev/null Thu Oct 22 01:47:20 2009 +++ julius4/msvc/SampleApp/SampleApp.cpp Thu Oct 22 01:47:20 2009 @@ -0,0 +1,231 @@ +// SampleApp.cpp +// + +#include "stdafx.h" +#include "SampleApp.h" +#include "Julius.h" + +// Use a Julius class +cJulius julius; + +#define MAX_LOADSTRING 100 + +// Global variables +HINSTANCE hInst; // Current interface +TCHAR szTitle[MAX_LOADSTRING]; // Text on the title bar +TCHAR szWindowClass[MAX_LOADSTRING]; // Main windows class name + +// Function prototype definitions +ATOM MyRegisterClass(HINSTANCE hInstance); +BOOL InitInstance(HINSTANCE, int); +LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); +INT_PTR CALLBACK About(HWND, UINT, WPARAM, LPARAM); + +int APIENTRY _tWinMain(HINSTANCE hInstance, + HINSTANCE hPrevInstance, + LPTSTR lpCmdLine, + int nCmdShow) +{ + UNREFERENCED_PARAMETER(hPrevInstance); + UNREFERENCED_PARAMETER(lpCmdLine); + + MSG msg; + HACCEL hAccelTable; + + LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING); + LoadString(hInstance, IDC_SAMPLEAPP, szWindowClass, MAX_LOADSTRING); + MyRegisterClass(hInstance); + + // Initialize application + if (!InitInstance (hInstance, nCmdShow)) + { + return FALSE; + } + + hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_SAMPLEAPP)); + + // Main message loop + while (GetMessage(&msg, NULL, 0, 0)) + { + if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg)) + { + TranslateMessage(&msg); + DispatchMessage(&msg); + } + } + + return (int) msg.wParam; +} + + + +// +// Function: MyRegisterClass() +// +// Register a window class. +// +ATOM MyRegisterClass(HINSTANCE hInstance) +{ + WNDCLASSEX wcex; + + wcex.cbSize = sizeof(WNDCLASSEX); + + wcex.style = CS_HREDRAW | CS_VREDRAW; + wcex.lpfnWndProc = WndProc; + wcex.cbClsExtra = 0; + wcex.cbWndExtra = 0; + wcex.hInstance = hInstance; + wcex.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_SAMPLEAPP)); + wcex.hCursor = LoadCursor(NULL, IDC_ARROW); + wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1); + wcex.lpszMenuName = MAKEINTRESOURCE(IDC_SAMPLEAPP); + wcex.lpszClassName = szWindowClass; + wcex.hIconSm = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_SMALL)); + + return RegisterClassEx(&wcex); +} + +// +// Function: InitInstance(HINSTANCE, int) +// +// Save instance handle and create a main window +// +BOOL InitInstance(HINSTANCE hInstance, int nCmdShow) +{ + HWND hWnd; + + // CHANGE THIS TO YOUR ENVIRONMENT AND YOUR MODEL ENCODING! + setlocale(LC_CTYPE, "Japanese_Japan.20932"); // Japanese EUC-JP + + hInst = hInstance; // store instance to global + + hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW, + CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL); + + if (!hWnd) + { + return FALSE; + } + + ShowWindow(hWnd, nCmdShow); + UpdateWindow(hWnd); + + return TRUE; +} + +// +// Function: WndProc(HWND, UINT, WPARAM, LPARAM) +// +// Process messages received at the main window +// +LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) +{ + int wmId, wmEvent; + PAINTSTRUCT ps; + HDC hdc; + int jEventId; + int jResultId; + + switch (message) + { + case WM_CREATE: + if (! julius.initialize("fast.jconf") ) { + MessageBox(hWnd, L"failed to initialize", L"Error", MB_OK); + break; + } + if (! julius.startProcess(hWnd)) { + MessageBox(hWnd, L"failed to start process", L"Error", MB_OK); + } + break; + case WM_JULIUS: + jEventId = LOWORD(wParam); + switch (jEventId) { + case JEVENT_ENGINE_ACTIVE: DebugOut(hWnd, L"Engine Active"); break; + case JEVENT_ENGINE_INACTIVE:DebugOut(hWnd, L"Engine Inactive"); break; + case JEVENT_ENGINE_PAUSE: DebugOut(hWnd, L"Engine Pause"); break; + case JEVENT_ENGINE_RESUME: DebugOut(hWnd, L"Engine Resume"); break; + case JEVENT_AUDIO_READY: DebugOut(hWnd, L"Audio Input Ready"); break; + case JEVENT_AUDIO_BEGIN: DebugOut(hWnd, L"Audio Input Begin"); break; + case JEVENT_AUDIO_END: DebugOut(hWnd, L"Audio Input End"); break; + case JEVENT_RECOG_BEGIN: DebugOut(hWnd, L"Recognition Begin"); break; + case JEVENT_RECOG_END: DebugOut(hWnd, L"Recognition End"); break; + case JEVENT_RECOG_FRAME: /*DebugOut(hWnd, L"Recognition Frame")*/; break; + case JEVENT_RESULT_FRAME: /* DebugOut(hWnd, L"Result Frame"); */ break; + case JEVENT_RESULT_PASS1: DebugOut(hWnd, L"Result Pass1"); break; + case JEVENT_RESULT_FINAL: DebugOut(hWnd, L"Result Final"); + jResultId = HIWORD(wParam); + if (jResultId < 0) { + DebugOut(hWnd, L"No result"); + } else { + DebugOut(hWnd, (wchar_t *)lParam); + } + break; + case JEVENT_GRAM_UPDATE: DebugOut(hWnd, L"Grammar changed"); break; + default: DebugOut(hWnd, L"! unknown event"); break; + } + //InvalidateRect(hWnd, NULL, TRUE); + break; + case WM_COMMAND: + wmId = LOWORD(wParam); + wmEvent = HIWORD(wParam); + switch (wmId) + { + case IDM_ABOUT: + DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About); + break; + case IDM_EXIT: + DestroyWindow(hWnd); + break; + case IDM_PAUSE: + julius.pause(); + break; + case IDM_RESUME: + julius.resume(); + break; + default: + return DefWindowProc(hWnd, message, wParam, lParam); + } + break; + case WM_PAINT: + hdc = BeginPaint(hWnd, &ps); + EndPaint(hWnd, &ps); + break; + case WM_DESTROY: + julius.stopProcess(); + PostQuitMessage(0); + break; + default: + return DefWindowProc(hWnd, message, wParam, lParam); + } + return 0; +} + +// Message handler for the version box +INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) +{ + UNREFERENCED_PARAMETER(lParam); + switch (message) + { + case WM_INITDIALOG: + return (INT_PTR)TRUE; + + case WM_COMMAND: + if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL) + { + EndDialog(hDlg, LOWORD(wParam)); + return (INT_PTR)TRUE; + } + break; + } + return (INT_PTR)FALSE; +} + +// Output a debug string to the main window +void DebugOut(HWND hWnd, wchar_t *str) +{ + static int line = 0; + HDC hdc = GetDC(hWnd); + TextOut(hdc , 10 , 10 + line * 20, str, lstrlen(str)); + ReleaseDC(hWnd , hdc); + if (++line > 22) line = 0; +} \ No newline at end of file Index: julius4/msvc/SampleApp/SampleApp.h diff -u /dev/null julius4/msvc/SampleApp/SampleApp.h:1.1 --- /dev/null Thu Oct 22 01:47:20 2009 +++ julius4/msvc/SampleApp/SampleApp.h Thu Oct 22 01:47:20 2009 @@ -0,0 +1,5 @@ +#pragma once + +#include "resource.h" + +void DebugOut(HWND hWnd, wchar_t *str); Index: julius4/msvc/SampleApp/SampleApp.ico Index: julius4/msvc/SampleApp/SampleApp.rc diff -u /dev/null julius4/msvc/SampleApp/SampleApp.rc:1.1 --- /dev/null Thu Oct 22 01:47:20 2009 +++ julius4/msvc/SampleApp/SampleApp.rc Thu Oct 22 01:47:20 2009 @@ -0,0 +1,155 @@ +//Microsoft Visual C++ Ŷ¬³ê½\[X XNvgÅ·B +// +#include "resource.h" + +#define APSTUDIO_READONLY_SYMBOLS +///////////////////////////////////////////////////////////////////////////// +// +// TEXTINCLUDE 2 \[X©ç¶¬³êܵ½B +// +#ifndef APSTUDIO_INVOKED +#include "targetver.h" +#endif +#define APSTUDIO_HIDDEN_SYMBOLS +#include "windows.h" +#undef APSTUDIO_HIDDEN_SYMBOLS +///////////////////////////////////////////////////////////////////////////// +#undef APSTUDIO_READONLY_SYMBOLS + +#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_JPN) +LANGUAGE 17, 1 +#pragma code_page(932) + +///////////////////////////////////////////////////////////////////////////// +// +// ACR +// + +// AvP[VÌACRð·×ÄÌVXeãÅÛ·é½ßÉAÅଳ¢ +// ID lÌACRªÅÉzu³êÜ·B + +IDI_SAMPLEAPP ICON "SampleApp.ico" +IDI_SMALL ICON "small.ico" + +///////////////////////////////////////////////////////////////////////////// +// +// j [ +// + +IDC_SAMPLEAPP MENU +BEGIN + POPUP "t@C(&F)" + BEGIN + MENUITEM "AvP[VÌI¹(&X)", IDM_EXIT + END + POPUP "ì(&M)" + BEGIN + MENUITEM "F¯f", IDM_PAUSE + MENUITEM "F¯ÄJ", IDM_RESUME + END + POPUP "wv(&H)" + BEGIN + MENUITEM "o[Wîñ(&A)...", IDM_ABOUT + END +END + + +///////////////////////////////////////////////////////////////////////////// +// +// ANZ[^ +// + +IDC_SAMPLEAPP ACCELERATORS +BEGIN + "?", IDM_ABOUT, ASCII, ALT + "/", IDM_ABOUT, ASCII, ALT +END + + +///////////////////////////////////////////////////////////////////////////// +// +// _CAO +// + +IDD_ABOUTBOX DIALOGEX 0, 0, 170, 62 +STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | WS_SYSMENU +CAPTION "o[Wîñ SampleApp" +FONT 9, "MS UI Gothic" +BEGIN + ICON IDR_MAINFRAME,IDC_STATIC,14,14,21,20 + LTEXT "SampleApp, Version 1.0",IDC_STATIC,42,14,114,8,SS_NOPREFIX + LTEXT "Copyright (C) 2009",IDC_STATIC,42,26,114,8 + DEFPUSHBUTTON "OK",IDOK,113,41,50,14,WS_GROUP +END + +///////////////////////////////////////////////////////////////////////////// +// +// DESIGNINFO +// + +#ifdef APSTUDIO_INVOKED +GUIDELINES DESIGNINFO +BEGIN + IDD_ABOUTBOX, DIALOG + BEGIN + LEFTMARGIN, 7 + RIGHTMARGIN, 163 + TOPMARGIN, 7 + BOTTOMMARGIN, 55 + END +END +#endif // APSTUDIO_INVOKED + +#ifdef APSTUDIO_INVOKED +///////////////////////////////////////////////////////////////////////////// +// +// TEXTINCLUDE +// +1 TEXTINCLUDE +BEGIN + "resource.h\0" +END + +2 TEXTINCLUDE +BEGIN + "#ifndef APSTUDIO_INVOKED\r\n" + "#include ""targetver.h""\r\n" + "#endif\r\n" + "#define APSTUDIO_HIDDEN_SYMBOLS\r\n" + "#include ""windows.h""\r\n" + "#undef APSTUDIO_HIDDEN_SYMBOLS\r\n" + "\0" +END + +3 TEXTINCLUDE +BEGIN + "\r\n" + "\0" +END + +#endif // APSTUDIO_INVOKED + +///////////////////////////////////////////////////////////////////////////// +// +// XgO e[u +// + +STRINGTABLE +BEGIN + IDC_SAMPLEAPP "SAMPLEAPP" + IDS_APP_TITLE "SampleApp" +END + +#endif +///////////////////////////////////////////////////////////////////////////// + + + +#ifndef APSTUDIO_INVOKED +///////////////////////////////////////////////////////////////////////////// +// +// TEXTINCLUDE 3 \[X©ç¶¬³êܵ½B +// + +///////////////////////////////////////////////////////////////////////////// +#endif // APSTUDIO_INVOKED ÅÈ¢ê Index: julius4/msvc/SampleApp/SampleApp.vcproj diff -u /dev/null julius4/msvc/SampleApp/SampleApp.vcproj:1.1 --- /dev/null Thu Oct 22 01:47:20 2009 +++ julius4/msvc/SampleApp/SampleApp.vcproj Thu Oct 22 01:47:20 2009 @@ -0,0 +1,261 @@ +<?xml version="1.0" encoding="shift_jis"?> +<VisualStudioProject + ProjectType="Visual C++" + Version="9.00" + Name="SampleApp" + ProjectGUID="{667FC1EB-6D97-4040-8ECE-A7B0E62B289B}" + RootNamespace="SampleApp" + Keyword="Win32Proj" + TargetFrameworkVersion="196613" + > + <Platforms> + <Platform + Name="Win32" + /> + </Platforms> + <ToolFiles> + </ToolFiles> + <Configurations> + <Configuration + Name="Debug|Win32" + OutputDirectory="$(SolutionDir)$(ConfigurationName)" + IntermediateDirectory="$(ConfigurationName)" + ConfigurationType="1" + CharacterSet="1" + > + <Tool + Name="VCPreBuildEventTool" + /> + <Tool + Name="VCCustomBuildTool" + /> + <Tool + Name="VCXMLDataGeneratorTool" + /> + <Tool + Name="VCWebServiceProxyGeneratorTool" + /> + <Tool + Name="VCMIDLTool" + /> + <Tool + Name="VCCLCompilerTool" + Optimization="0" + AdditionalIncludeDirectories="../config;../../libjulius/include;../../libsent/include" + PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_CRT_SECURE_NO_WARNINGS" + MinimalRebuild="true" + BasicRuntimeChecks="3" + RuntimeLibrary="3" + UsePrecompiledHeader="0" + WarningLevel="3" + DebugInformationFormat="4" + DisableSpecificWarnings="4819" + /> + <Tool + Name="VCManagedResourceCompilerTool" + /> + <Tool + Name="VCResourceCompilerTool" + /> + <Tool + Name="VCPreLinkEventTool" + /> + <Tool + Name="VCLinkerTool" + AdditionalDependencies="libjulius.lib libsent.lib ws2_32.lib zlib.lib" + LinkIncremental="2" + AdditionalLibraryDirectories="../Debug;../portaudio;../zlib" + GenerateDebugInformation="true" + SubSystem="2" + TargetMachine="1" + /> + <Tool + Name="VCALinkTool" + /> + <Tool + Name="VCManifestTool" + /> + <Tool + Name="VCXDCMakeTool" + /> + <Tool + Name="VCBscMakeTool" + /> + <Tool + Name="VCFxCopTool" + /> + <Tool + Name="VCAppVerifierTool" + /> + <Tool + Name="VCPostBuildEventTool" + /> + </Configuration> + <Configuration + Name="Release|Win32" + OutputDirectory="$(SolutionDir)$(ConfigurationName)" + IntermediateDirectory="$(ConfigurationName)" + ConfigurationType="1" + CharacterSet="1" + WholeProgramOptimization="1" + > + <Tool + Name="VCPreBuildEventTool" + /> + <Tool + Name="VCCustomBuildTool" + /> + <Tool + Name="VCXMLDataGeneratorTool" + /> + <Tool + Name="VCWebServiceProxyGeneratorTool" + /> + <Tool + Name="VCMIDLTool" + /> + <Tool + Name="VCCLCompilerTool" + Optimization="2" + EnableIntrinsicFunctions="true" + AdditionalIncludeDirectories="../config;../../libjulius/include;../../libsent/include" + PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_CRT_SECURE_NO_WARNINGS" + RuntimeLibrary="2" + EnableFunctionLevelLinking="true" + UsePrecompiledHeader="0" + WarningLevel="3" + DebugInformationFormat="3" + DisableSpecificWarnings="4819" + /> + <Tool + Name="VCManagedResourceCompilerTool" + /> + <Tool + Name="VCResourceCompilerTool" + /> + <Tool + Name="VCPreLinkEventTool" + /> + <Tool + Name="VCLinkerTool" + AdditionalDependencies="libjulius.lib libsent.lib ws2_32.lib zlib.lib" + LinkIncremental="1" + AdditionalLibraryDirectories="../Release;../portaudio;../zlib" + GenerateDebugInformation="true" + SubSystem="2" + OptimizeReferences="2" + EnableCOMDATFolding="2" + TargetMachine="1" + /> + <Tool + Name="VCALinkTool" + /> + <Tool + Name="VCManifestTool" + /> + <Tool + Name="VCXDCMakeTool" + /> + <Tool + Name="VCBscMakeTool" + /> + <Tool + Name="VCFxCopTool" + /> + <Tool + Name="VCAppVerifierTool" + /> + <Tool + Name="VCPostBuildEventTool" + /> + </Configuration> + </Configurations> + <References> + </References> + <Files> + <Filter + Name="\[X t@C" + Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx" + UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}" + > + <File + RelativePath=".\Julius.cpp" + > + </File> + <File + RelativePath=".\Julius.h" + > + </File> + <File + RelativePath=".\SampleApp.cpp" + > + </File> + <File + RelativePath=".\stdafx.cpp" + > + <FileConfiguration + Name="Debug|Win32" + > + <Tool + Name="VCCLCompilerTool" + UsePrecompiledHeader="1" + /> + </FileConfiguration> + <FileConfiguration + Name="Release|Win32" + > + <Tool + Name="VCCLCompilerTool" + UsePrecompiledHeader="1" + /> + </FileConfiguration> + </File> + </Filter> + <Filter + Name="wb_[ t@C" + Filter="h;hpp;hxx;hm;inl;inc;xsd" + UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}" + > + <File + RelativePath=".\Resource.h" + > + </File> + <File + RelativePath=".\SampleApp.h" + > + </File> + <File + RelativePath=".\stdafx.h" + > + </File> + <File + RelativePath=".\targetver.h" + > + </File> + </Filter> + <Filter + Name="\[X t@C" + Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav" + UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}" + > + <File + RelativePath=".\SampleApp.ico" + > + </File> + <File + RelativePath=".\SampleApp.rc" + > + </File> + <File + RelativePath=".\small.ico" + > + </File> + </Filter> + <File + RelativePath=".\ReadMe.txt" + > + </File> + </Files> + <Globals> + </Globals> +</VisualStudioProject> Index: julius4/msvc/SampleApp/small.ico Index: julius4/msvc/SampleApp/stdafx.cpp diff -u /dev/null julius4/msvc/SampleApp/stdafx.cpp:1.1 --- /dev/null Thu Oct 22 01:47:20 2009 +++ julius4/msvc/SampleApp/stdafx.cpp Thu Oct 22 01:47:20 2009 @@ -0,0 +1,8 @@ +// stdafx.cpp : WCN[h SampleApp.pch ÌÝð +// ÜÞ\[X t@CÍAvRpCÏÝwb_[ÉÈèÜ·B +// stdafx.obj ÉÍvRpCÏÝ^îñªÜÜêÜ·B + +#include "stdafx.h" + +// TODO: ±Ìt@CÅÍÈASTDAFX.H ÅKvÈ +// ÇÁwb_[ðQƵľ³¢B Index: julius4/msvc/SampleApp/stdafx.h diff -u /dev/null julius4/msvc/SampleApp/stdafx.h:1.1 --- /dev/null Thu Oct 22 01:47:20 2009 +++ julius4/msvc/SampleApp/stdafx.h Thu Oct 22 01:47:20 2009 @@ -0,0 +1,22 @@ +// stdafx.h : WÌVXe CN[h t@CÌCN[h t@CAÜ½Í +// QÆñª½A©Â ÜèÏX³êÈ¢AvWFNgêpÌCN[h t@C +// ðLqµÜ·B +// + +#pragma once + +#include "targetver.h" + +#define WIN32_LEAN_AND_MEAN // Windows wb_[©çgp³êĢȢªðOµÜ·B +// Windows wb_[ t@C: +#include <windows.h> + +// C ^C wb_[ t@C +#include <stdlib.h> +#include <malloc.h> +#include <memory.h> +#include <tchar.h> + + +// TODO: vOÉKvÈÇÁwb_[ð±±ÅQƵľ³¢B +#include <locale.h> \ No newline at end of file Index: julius4/msvc/SampleApp/targetver.h diff -u /dev/null julius4/msvc/SampleApp/targetver.h:1.1 --- /dev/null Thu Oct 22 01:47:20 2009 +++ julius4/msvc/SampleApp/targetver.h Thu Oct 22 01:47:20 2009 @@ -0,0 +1,24 @@ +#pragma once + +// ȺÌ}NÍAÅáÀKvÈvbgtH[ðè`µÜ·BÅáÀKvÈvbgtH[ÆÍA +// AvP[VðÀs·é½ßÉKvÈ@\ðõ¦½Åàâo[WÌ Windows â Internet Explorer ÈÇ +// ð¢¢Ü·B±êçÌ}NÍAwèµ½o[WÆA»êÈOÌo[WÌvbgtH[ãÅpÅ«é·×ÄÌ@\ðLøÉ·é±ÆÉæÁÄ +// ®ìµÜ·B + +// ºÅwè³ê½è`ÌOÉÎÛvbgtH[ðwèµÈ¯êÎÈçÈ¢êAȺÌè`ðÏXµÄ¾³¢B +// ÙÈévbgtH[ÉηélÉÖ·éÅVîñÉ¢ÄÍAMSDN ðQƵľ³¢B +#ifndef WINVER // ÅáÀKvÈvbgtH[ª Windows Vista Å é±ÆðwèµÜ·B +#define WINVER 0x0600 // ±êð Windows ̼Ìo[Wü¯ÉKØÈlÉÏXµÄ¾³¢B +#endif + +#ifndef _WIN32_WINNT // ÅáÀKvÈvbgtH[ª Windows Vista Å é±ÆðwèµÜ·B +#define _WIN32_WINNT 0x0600 // ±êð Windows ̼Ìo[Wü¯ÉKØÈlÉÏXµÄ¾³¢B +#endif + +#ifndef _WIN32_WINDOWS // ÅáÀKvÈvbgtH[ª Windows 98 Å é±ÆðwèµÜ·B +#define _WIN32_WINDOWS 0x0410 // ±êð Windows Me ܽͻêÈ~Ìo[Wü¯ÉKØÈlÉÏXµÄ¾³¢B +#endif + +#ifndef _WIN32_IE // ÅáÀKvÈvbgtH[ª Internet Explorer 7.0 Å é±ÆðwèµÜ·B +#define _WIN32_IE 0x0700 // ±êð IE ̼Ìo[Wü¯ÉKØÈlÉÏXµÄ¾³¢B +#endif