コード例 #1
0
void FileManipulating::CreateHMMFile(System::String *exeFileDir, System::String *outputHmmDir, System::String *prototypeFile, System::String *trainFile)
{
	try
	{
		System::String* batchFileName = outputHmmDir + "\\" +"_HInit.bat";
		System::IO::StreamWriter* sw = new System::IO::StreamWriter(batchFileName);
		System::String* tempStr = "";

		// building the associate command for the initialization
		tempStr += "\"" + exeFileDir + "HInit" + "\"";
		tempStr += " -m 1";			// required for training from single sample
		tempStr += " -M ";
		tempStr += "\"" + outputHmmDir + "\"";
		tempStr += " ";
		tempStr += "\"" + prototypeFile + "\"";
		tempStr += " ";
		tempStr += "\"" + trainFile + "\"";
		
		sw->Write(tempStr);
		sw->Close();

		// create a process and execute 
		System::Diagnostics::Process* p = new System::Diagnostics::Process();
		p->StartInfo->FileName = batchFileName;
		p->Start();
		p->WaitForExit();
	}
	catch (System::Exception* excp)
    {
//		System::Windows::Forms::MessageBox::Show(excp->Message->ToString(),"Can't Create HMM Training File!!",System::Windows::Forms::MessageBoxButtons::OK,System::Windows::Forms::MessageBoxIcon::Error);
		exit(0);
    }	
}
コード例 #2
0
void FileManipulating::RecognizeByHMM(System::String* recDir, System::String* execFile, System::String *mmfFile, System::String *mlfFile, System::String *wdNetFile, System::String *dictFile, System::String* hmmListFile, System::String *scriptFile)
{
	try
	{
		System::String* batchFileName = recDir + "_HVite.bat";
		System::IO::StreamWriter* sw = new System::IO::StreamWriter(batchFileName);
		System::String* tempStr = "";

		// building the associate command for the initialization
		tempStr += "\"" + execFile + "HVite" + "\"";
		tempStr += " -H ";			// required for training from single sample
		tempStr += "\"" + mmfFile + "\"";
		tempStr += " -i ";
		tempStr += "\"" + mlfFile + "\"";
		tempStr += " -w ";
		tempStr += "\"" + wdNetFile + "\"";
		tempStr += " ";
		tempStr += "\"" + dictFile + "\"";
		tempStr += " ";
		tempStr += "\"" + hmmListFile + "\"";
		tempStr += " -S ";
		tempStr += "\"" + scriptFile + "\"";
		
		sw->Write(tempStr);
		sw->Close();

		// create a process and execute 
		System::Diagnostics::Process* p = new System::Diagnostics::Process();
		p->StartInfo->FileName = batchFileName;
		p->Start();
		p->WaitForExit();
	}
	catch (System::Exception* excp)
    {
//		Forms::MessageBox::Show(excp->Message->ToString(),"Can't Create/Execute Viterbi Decoder!!",System::Windows::Forms::MessageBoxButtons::OK,System::Windows::Forms::MessageBoxIcon::Error);
		exit(0);
    }
}
コード例 #3
0
void FileManipulating::BuildWordNetwork(System::String *gramFile, System::String *dictFile, System::String *transFile, System::String *wdnetFileDir, System::String* execpath, System::String* modelName)
{
	System::IO::StreamWriter* sw = System::IO::StreamWriter::Null;
	try
	{
		// add model name to the grammer file
		System::String* text = "";
		// check the existance of grammer file
		if(!System::IO::File::Exists(gramFile))
		{
			sw = new System::IO::StreamWriter(gramFile);
			text = "$WORD = "+ modelName + ";" + "\n" + "([$WORD])";
			sw->Write(text);
			sw->Close();
		}
		else
		{
			// create streamreader
			System::IO::StreamReader* sr = new System::IO::StreamReader(gramFile);
			System::String* line;
			int  k;

			// Read and display lines from the file until the end of 
			// the file is reached.
			line=sr->ReadLine();
			while (line->Length!=0) 
			{
				k = line->IndexOf(";");
				if(k < 0 )
				{
					text += line+"\n";
				}
				else
				{
					line = line->Substring(0,k);
					text += line + "|" + modelName + ";" + "\n";
				}
				line=sr->ReadLine();
			}
			sr->Close();
			// write to the grammer file
			sw = new System::IO::StreamWriter(gramFile);
			sw->Write(text);
			sw->Close();
		}
		
		// add model name to the dictionary file
		
		sw = System::IO::File::AppendText(dictFile);
		modelName = modelName + " [" + modelName + "] " + modelName;
		sw->WriteLine(modelName);
		sw->Close();

		// add model name & associated transcription to the transcripton database file

		// build the world network
		/*1. Creating _HParse.bat*/
		System::String* parseFile = wdnetFileDir + "_HParse.bat";
		sw = new System::IO::StreamWriter(parseFile);
		text = "\"" + execpath + "HParse" + "\"" + " ";
		text += "\"" + gramFile + "\"" + " ";
		text += "\"" + wdnetFileDir + "net.slf" + "\"";
		sw->Write(text);
		sw->Close();
		
		/*2. Creating _HSGen.bat*/
		System::String* genFile = wdnetFileDir + "_HSGen.bat";
		sw = new System::IO::StreamWriter(genFile);
		text = "\"" + execpath + "HSGen" + "\"" + " ";
		text += "\"" + wdnetFileDir + "net.slf" + "\"" + " ";
		text += "\"" + dictFile + "\"";
		sw->Write(text);
		sw->Close();

		// create a process and execute the batch files
		System::Diagnostics::Process* p = new System::Diagnostics::Process();
		// execute _HParse.bat
		p->StartInfo->FileName = parseFile;
		p->Start();
		p->WaitForExit();

		// execute _HSGen.bat
		p->StartInfo->FileName = genFile;
		p->Start();
		p->WaitForExit();
	}
	catch(System::Exception* ex)
	{
		//System::Windows::Forms::MessageBox::Show(ex->Message->ToString(),"Building Word Network Failed!!",System::Windows::Forms::MessageBoxButtons::OK,System::Windows::Forms::MessageBoxIcon::Error);
		exit(0);
	}
}