[Julius-cvs 478] CVS update: julius4/msvc/SampleApp

アーカイブの一覧に戻る

sumom****@users***** sumom****@users*****
2009年 10月 23日 (金) 09:31:12 JST


Index: julius4/msvc/SampleApp/SampleApp.cpp
diff -u julius4/msvc/SampleApp/SampleApp.cpp:1.2 julius4/msvc/SampleApp/SampleApp.cpp:1.3
--- julius4/msvc/SampleApp/SampleApp.cpp:1.2	Thu Oct 22 23:04:11 2009
+++ julius4/msvc/SampleApp/SampleApp.cpp	Fri Oct 23 09:31:12 2009
@@ -5,9 +5,6 @@
 #include "SampleApp.h"
 #include "Julius.h"
 
-// The jconf file name to load
-#define JCONFFILE "default.jconf"
-
 // Use a Julius class
 cJulius julius;
 
@@ -117,6 +114,40 @@
 }
 
 //
+//  Function: GetJconfFileName( char *, int )
+//
+//  Open file dialog to get jconf file name
+//
+#include "CommDlg.h"
+bool GetJconfFileName( char *buf, int buflen )
+{
+	wchar_t	wszFileName[MAX_PATH];
+	bool ret;
+	static OPENFILENAME ofn;
+
+	ZeroMemory( &wszFileName, sizeof(wchar_t) * MAX_PATH );
+	ZeroMemory( &ofn, sizeof(OPENFILENAME) );
+	ofn.lStructSize = sizeof(OPENFILENAME);
+	ofn.hwndOwner = NULL;
+	ofn.lpstrFilter = L"Jconf File(*.jconf)\0*.jconf\0\0";
+	ofn.lpstrFile = wszFileName;
+	ofn.nMaxFile = MAX_PATH;
+	ofn.Flags = OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
+	ofn.lpstrDefExt = L"jconf";
+	ofn.lpstrTitle = L"Open Jconf";
+
+	if( GetOpenFileName( &ofn ) ) {
+		// convert wide-char to multi-byte char (limitation of JuliusLib...)
+		size_t converted = 0;
+		wcstombs_s(&converted, buf, buflen, wszFileName, _TRUNCATE);
+		ret = true;
+	} else {
+		ret = false;
+	}
+	return ret;
+}
+
+//
 //  Function: WndProc(HWND, UINT, WPARAM, LPARAM)
 //
 //  Process messages received at the main window
@@ -128,19 +159,11 @@
 	HDC hdc;
 	int jEventId;
 	int jResultId;
+	static char conffile[1024];
 
 	switch (message)
 	{
 	case WM_CREATE:
-		// initialize Julius engine to prepare for recognition
-		if (! julius.initialize( JCONFFILE ) ) {
-			MessageBox(hWnd, L"Error while loading Julius engine.\n\"default.jconf\" is missing or some configurations are wrong\n", L"Error", MB_OK);
-			break;
-		}
-		// start recognition
-		if (! julius.startProcess(hWnd)) {
-			MessageBox(hWnd, L"failed to start process", L"Error", MB_OK);
-		}
 		break;
 	case WM_JULIUS:
 		jEventId = LOWORD(wParam);
@@ -175,18 +198,43 @@
 		wmEvent = HIWORD(wParam);
 		switch (wmId)
 		{
-		case IDM_ABOUT:
-			DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About);
+		case IDM_OPENJCONF:
+			// (re-)open jconf file and prepare for recognition
+			if (GetJconfFileName( conffile, 1024 )) {
+				// initialize Julius engine to prepare for recognition
+				DebugOut(hWnd, L"Loading Julius Engine...");
+				if (! julius.initialize( conffile ) ) {
+					MessageBox(hWnd, L"Error while loading Julius engine.\n", L"Error", MB_OK);
+					break;
+				}
+				DebugOut(hWnd, L"Done.");
+				DebugOut(hWnd, L"Do [Command]-[Start] to start recognition.");
+			}
 			break;
-		case IDM_EXIT:
-			DestroyWindow(hWnd);
+		case IDM_STARTPROCESS:
+			// open audio stream and start recognition thread
+			if (! julius.startProcess(hWnd)) {
+				MessageBox(hWnd, L"failed to start process", L"Error", MB_OK);
+			}
+			break;
+		case IDM_STOPPROCESS:
+			// close audio stream and finish recognition thread
+			julius.stopProcess();
 			break;
 		case IDM_PAUSE:
+			// pause engine
 			julius.pause();
 			break;
 		case IDM_RESUME:
+			// resume paused engine
 			julius.resume();
 			break;
+		case IDM_ABOUT:
+			DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About);
+			break;
+		case IDM_EXIT:
+			DestroyWindow(hWnd);
+			break;
 		default:
 			return DefWindowProc(hWnd, message, wParam, lParam);
 		}
@@ -196,7 +244,6 @@
 		EndPaint(hWnd, &ps);
 		break;
 	case WM_DESTROY:
-		julius.stopProcess();
 		PostQuitMessage(0);
 		break;
 	default:
Index: julius4/msvc/SampleApp/Resource.h
diff -u julius4/msvc/SampleApp/Resource.h:1.1 julius4/msvc/SampleApp/Resource.h:1.2
--- julius4/msvc/SampleApp/Resource.h:1.1	Thu Oct 22 01:47:20 2009
+++ julius4/msvc/SampleApp/Resource.h	Fri Oct 23 09:31:12 2009
@@ -18,8 +18,11 @@
 #define IDC_STATIC				-1
 #endif
 
-#define IDM_PAUSE                       32771
-#define IDM_RESUME                      32772
+#define IDM_OPENJCONF			32771
+#define IDM_STARTPROCESS		32772
+#define IDM_STOPPROCESS			32773
+#define IDM_PAUSE                       32774
+#define IDM_RESUME                      32775
 
 // V‚µ‚¢ƒIƒuƒWƒFƒNƒg‚ÌŽŸ‚ÌŠù’è’l
 //
@@ -28,7 +31,7 @@
 
 #define _APS_NO_MFC					130
 #define _APS_NEXT_RESOURCE_VALUE	129
-#define _APS_NEXT_COMMAND_VALUE		32773
+#define _APS_NEXT_COMMAND_VALUE		32776
 #define _APS_NEXT_CONTROL_VALUE		1000
 #define _APS_NEXT_SYMED_VALUE		110
 #endif
Index: julius4/msvc/SampleApp/SampleApp.rc
diff -u julius4/msvc/SampleApp/SampleApp.rc:1.2 julius4/msvc/SampleApp/SampleApp.rc:1.3
--- julius4/msvc/SampleApp/SampleApp.rc:1.2	Thu Oct 22 20:02:41 2009
+++ julius4/msvc/SampleApp/SampleApp.rc	Fri Oct 23 09:31:12 2009
@@ -40,12 +40,15 @@
 BEGIN
     POPUP "File (&F)"
     BEGIN
+	MENUITEM "Open Jconf... (&O)",       IDM_OPENJCONF
         MENUITEM "Quit (&X)",                IDM_EXIT
     END
     POPUP "Command (&M)"
     BEGIN
-        MENUITEM "Pause recognition",                IDM_PAUSE
-        MENUITEM "Resume recognition",               IDM_RESUME
+	MENUITEM "Start",               IDM_STARTPROCESS
+        MENUITEM "Finish",              IDM_STOPPROCESS
+        MENUITEM "Pause",               IDM_PAUSE
+        MENUITEM "Resume",              IDM_RESUME
     END
     POPUP "Help (&H)"
     BEGIN



Julius-cvs メーリングリストの案内
アーカイブの一覧に戻る