sumom****@users*****
sumom****@users*****
2009年 10月 22日 (木) 20:02:41 JST
Index: julius4/msvc/SampleApp/Julius.cpp diff -u julius4/msvc/SampleApp/Julius.cpp:1.1 julius4/msvc/SampleApp/Julius.cpp:1.2 --- julius4/msvc/SampleApp/Julius.cpp:1.1 Thu Oct 22 01:47:20 2009 +++ julius4/msvc/SampleApp/Julius.cpp Thu Oct 22 20:02:41 2009 @@ -1,25 +1,24 @@ #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); +// ----------------------------------------------------------------------------- +// JuliusLib callback functions +// + +#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) +// callback to get result static void callback_result_final(Recog *recog, void *data) { cJulius *j = (cJulius *)data; @@ -68,36 +67,34 @@ str[0] = '\0'; for(i=0;i<seqnum;i++) strcat(str, winfo->woutput[seq[i]]); + // convert to wide char mbstowcs_s( &size, wstr, str, strlen(str)+1); + // set status parameter wparam = (r->result.status << 16) + JEVENT_RESULT_FINAL; + // send message SendMessage(j->getWindow(), WM_JULIUS, wparam, (LPARAM)wstr); } -// |[Ypâ~Ö - +// callbackk for pause static void callback_wait_for_resume(Recog *recog, void *data) { cJulius *j = (cJulius *)data; - // ±ÌXbhiF¯XbhjÌÀsðf + // Stop running the engine thread SuspendThread( j->getThreadHandle() ); - // ÊXbh©çResumeThread()ªÄÎêéÜÅÒ@ + // the engine thread will wait until the main thread calls ResumeThread() for it } -//----------------------------------------------------------------------------------------- - #ifdef APP_ADIN static int callback_adin_fetch_input(SP16 *sampleBuffer, int reqlen) { - // ¤Lobt@ÉV½È«Ýª é©A é¢ÍOñÌcèª é©`FbN - // êλêðÅå reqlen ¾¯ sampleBuffer É«Þ + // If shared audio buffer has some new data, or some data remains from the last call, + // get the samples into sampleBuffer at most reqlen length. } #endif -//----------------------------------------------------------------------------------------- - -// F¯XbhÌCÖ +// main function for the engine thread DWORD WINAPI recogThreadMain(LPVOID vdParam) { int ret; @@ -108,12 +105,12 @@ } //----------------------------------------------------------------------------------------- +// Julius class definition //----------------------------------------------------------------------------------------- - -//================ -// RXgN^ -//================ +//============= +// Constructor +//============= cJulius::cJulius( void ) : m_jconf( NULL ), m_recog( NULL ), m_opened( false ), m_threadHandle( NULL ), m_fpLogFile( NULL ) { #ifdef APP_ADIN @@ -122,9 +119,9 @@ setLogFile( "juliuslog.txt" ); } -//============== -// fXgN^ -//============== +//============ +// Destructor +//============ cJulius::~cJulius( void ) { release(); @@ -134,9 +131,9 @@ } } -//========= -// ú»1 -//========= +//================================= +// Initialize, with argument array +//================================= bool cJulius::initialize( int argnum, char *argarray[]) { bool ret; @@ -154,9 +151,9 @@ return ret; } -//========= -// ú»2 -//========= +//=============================== +// Initialize, with a Jconf file +//=============================== bool cJulius::initialize( char *filename ) { bool ret; @@ -170,9 +167,9 @@ return ret; } -//========= -// ú»2 -//========= +//=================== +// Load a Jconf file +//=================== bool cJulius::loadJconf( char *filename ) { if (m_jconf) { @@ -188,9 +185,9 @@ return true; } -//================== -// Ot@CoÍ -//================== +//============================================== +// Set a log file to save Julius engine outputs +//============================================== void cJulius::setLogFile( const char *filename ) { if (m_fpLogFile) { @@ -202,9 +199,9 @@ } } -//================ -// GWú» -//================ +//======================== +// Create engine instance +//======================== bool cJulius::createEngine( void ) { #ifdef APP_ADIN @@ -216,7 +213,6 @@ #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; @@ -232,13 +228,13 @@ } #endif - // GWðN® + // Create engine instance m_recog = j_create_instance_from_jconf(m_jconf); if (m_recog == NULL) { return false; } - // R[obNðo^ + // Register callbacks 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); @@ -253,9 +249,8 @@ callback_add(m_recog, CALLBACK_PAUSE_FUNCTION, ::callback_wait_for_resume, this); #ifdef APP_ADIN - // ¹ºüÍfoCXðú» + // Initialize application side audio input if (m_appsource != 0) { - // AvüÍpÉ©OÅú» a = m_recog->adin; switch(m_appsource) { case 1: // buffer input, batch @@ -289,7 +284,7 @@ if (adin_setup_param(a, m_recog->jconf) == FALSE) return false; a->input_side_segment = FALSE; } else { - // JuliusLib Éú»ðC¹é + // Let JuliusLib get audio input if (! j_adin_init( m_recog ) ) return false; } #else @@ -299,9 +294,9 @@ return true; } -//==================== -// ðJn·é -//==================== +//============================================== +// Open stream and start the recognition thread +//============================================== bool cJulius::startProcess( HWND hWnd ) { @@ -336,42 +331,43 @@ return true; } -//================ -// ðI¹·é -//================ +//================================================== +// Close audio stream and detach recognition thread +//================================================== void cJulius::stopProcess( void ) { if (m_opened) { - // Xg[ð¶éiXbhÍI¹·é͸j + // recognition thread will exit when audio input is closed j_close_stream(m_recog); m_opened = false; } } -//========== -// êâ~ -//========== +//=================== +// Pause recognition +//=================== void cJulius::pause( void ) { - // â~ðv - // ~ÜÁ½çAF¯XbhÍ pause Cxgøã PAUSE_FUNCTION R[obNðÀs + // request library to pause + // After pause, the recognition thread will issue pause event + // and then enter callback_wait_for_resume(), where thread will pause. j_request_terminate(m_recog); } -//========== -// ®ìÄJ -//========== +//==================== +// Resume recognition +//==================== void cJulius::resume( void ) { - // ÄJvðæÉZbg + // request library to resume j_request_resume(m_recog); - // F¯XbhÌ®ìðÄJBF¯XbhÍ resume CxgøãF¯ðÄJ·é + // resume the recognition thread ResumeThread( m_threadHandle ); } -//============== -// ¶@ÇÝÝ -//============== +//================== +// Load DFA grammar +//================== bool cJulius::loadGrammar( WORD_INFO *winfo, DFA_INFO *dfa, char *dictfile, char *dfafile, RecogProcess *r ) { boolean ret; @@ -403,9 +399,9 @@ return true; } -//============== -// ¶@ÇÁ -//============== +//================= +// Add DFA grammar +//================= bool cJulius::addGrammar( char *name, char *dictfile, char *dfafile, bool deleteAll ) { WORD_INFO *winfo; @@ -452,16 +448,16 @@ } //============== -// ¶@üêÖ¦ +// Swap grammar //============== bool cJulius::changeGrammar( char *name, char *dictfile, char *dfafile ) { return addGrammar(name, dictfile, dfafile, true); } -//============== -// ¶@í -//============== +//============================ +// Delete grammar by its name +//============================ bool cJulius::deleteGrammar( char *name ) { RecogProcess *r = m_recog->process_list; @@ -482,9 +478,9 @@ return true; } -//============== -// ¶@ê³ø -//============== +//================================ +// Deactivate grammar by its name +//================================ bool cJulius::deactivateGrammar( char *name ) { RecogProcess *r = m_recog->process_list; @@ -508,9 +504,10 @@ return true; } -//==================== -// ¶@ê³øðð -//==================== + +//================================= +// Re-activate grammar by its name +//================================= bool cJulius::activateGrammar( char *name ) { RecogProcess *r = m_recog->process_list; @@ -535,9 +532,9 @@ return true; } -//========= -// ðú -//========= +//===================================== +// Stop processes and release all data +//===================================== void cJulius::release( void ) { stopProcess(); Index: julius4/msvc/SampleApp/Julius.h diff -u julius4/msvc/SampleApp/Julius.h:1.1 julius4/msvc/SampleApp/Julius.h:1.2 --- julius4/msvc/SampleApp/Julius.h:1.1 Thu Oct 22 01:47:20 2009 +++ julius4/msvc/SampleApp/Julius.h Thu Oct 22 20:02:41 2009 @@ -1,25 +1,15 @@ -// -// 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è` +// for development codes: do not define this #undef APP_ADIN -// [Uè`Cxg +// Julius event identifier #define WM_JULIUS (WM_USER + 1) -// CxgID +// Event ID enum { JEVENT_ENGINE_ACTIVE, JEVENT_ENGINE_INACTIVE, Index: julius4/msvc/SampleApp/SampleApp.rc diff -u julius4/msvc/SampleApp/SampleApp.rc:1.1 julius4/msvc/SampleApp/SampleApp.rc:1.2 --- julius4/msvc/SampleApp/SampleApp.rc:1.1 Thu Oct 22 01:47:20 2009 +++ julius4/msvc/SampleApp/SampleApp.rc Thu Oct 22 20:02:41 2009 @@ -1,11 +1,11 @@ -//Microsoft Visual C++ Ŷ¬³ê½\[X XNvgÅ·B +//This is a resource script generated by Microsoft Visual C++ // #include "resource.h" #define APSTUDIO_READONLY_SYMBOLS ///////////////////////////////////////////////////////////////////////////// // -// TEXTINCLUDE 2 \[X©ç¶¬³êܵ½B +// Generated from TEXTINCLUDE 2 resources // #ifndef APSTUDIO_INVOKED #include "targetver.h" @@ -22,41 +22,41 @@ ///////////////////////////////////////////////////////////////////////////// // -// ACR +// Icons // -// AvP[VÌACRð·×ÄÌVXeãÅÛ·é½ßÉAÅଳ¢ -// ID lÌACRªÅÉzu³êÜ·B +// In order to allocate an application icon in all systems, the icon +// with the smallest ID value will be placed first. -IDI_SAMPLEAPP ICON "SampleApp.ico" -IDI_SMALL ICON "small.ico" +// IDI_SAMPLEAPP ICON "SampleApp.ico" +// IDI_SMALL ICON "small.ico" ///////////////////////////////////////////////////////////////////////////// // -// j [ +// Menu // IDC_SAMPLEAPP MENU BEGIN - POPUP "t@C(&F)" + POPUP "File (&F)" BEGIN - MENUITEM "AvP[VÌI¹(&X)", IDM_EXIT + MENUITEM "Quit (&X)", IDM_EXIT END - POPUP "ì(&M)" + POPUP "Command (&M)" BEGIN - MENUITEM "F¯f", IDM_PAUSE - MENUITEM "F¯ÄJ", IDM_RESUME + MENUITEM "Pause recognition", IDM_PAUSE + MENUITEM "Resume recognition", IDM_RESUME END - POPUP "wv(&H)" + POPUP "Help (&H)" BEGIN - MENUITEM "o[Wîñ(&A)...", IDM_ABOUT + MENUITEM "About (&A)...", IDM_ABOUT END END ///////////////////////////////////////////////////////////////////////////// // -// ANZ[^ +// Accelerators // IDC_SAMPLEAPP ACCELERATORS @@ -68,13 +68,13 @@ ///////////////////////////////////////////////////////////////////////////// // -// _CAO +// Dialog // 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" +CAPTION "About 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 @@ -131,7 +131,7 @@ ///////////////////////////////////////////////////////////////////////////// // -// XgO e[u +// String table // STRINGTABLE @@ -148,8 +148,8 @@ #ifndef APSTUDIO_INVOKED ///////////////////////////////////////////////////////////////////////////// // -// TEXTINCLUDE 3 \[X©ç¶¬³êܵ½B +// Generated from TEXTINCLUDE 3 resources // ///////////////////////////////////////////////////////////////////////////// -#endif // APSTUDIO_INVOKED ÅÈ¢ê +#endif // not APSTUDIO_INVOKED Index: julius4/msvc/SampleApp/SampleApp.vcproj diff -u julius4/msvc/SampleApp/SampleApp.vcproj:1.1 julius4/msvc/SampleApp/SampleApp.vcproj:1.2 --- julius4/msvc/SampleApp/SampleApp.vcproj:1.1 Thu Oct 22 01:47:20 2009 +++ julius4/msvc/SampleApp/SampleApp.vcproj Thu Oct 22 20:02:41 2009 @@ -246,10 +246,6 @@ RelativePath=".\SampleApp.rc" > </File> - <File - RelativePath=".\small.ico" - > - </File> </Filter> <File RelativePath=".\ReadMe.txt"