You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
141 lines
3.8 KiB
141 lines
3.8 KiB
|
|
#include "RecognitionCLRDll.h"
|
|
#include <msclr\marshal_cppstd.h>
|
|
|
|
using namespace msclr::interop;
|
|
|
|
using namespace System;
|
|
using namespace System::Runtime::InteropServices;
|
|
|
|
|
|
|
|
namespace RecognitionCLRDll {
|
|
|
|
RecognizerCLR::RecognizerCLR() {
|
|
//m_pRecognizer = new OnlineRecognizerDemo();
|
|
mEnablePartial = false;
|
|
}
|
|
|
|
RecognizerCLR::~RecognizerCLR() {
|
|
//m_pRecognizer = nullptr;
|
|
}
|
|
|
|
//
|
|
char* ManagedString2UnmanagedStringA(String^ strIn)
|
|
{
|
|
IntPtr ip = Marshal::StringToHGlobalAnsi(strIn);
|
|
const char* pTemp = static_cast<const char*>(ip.ToPointer());
|
|
char *pOut = new char[strlen(pTemp) + 1];
|
|
strcpy_s(pOut, strlen(pTemp) + 1, pTemp);
|
|
Marshal::FreeHGlobal(ip);
|
|
return pOut;
|
|
}
|
|
|
|
std::string SystemStringToStdString(System::String^ sData)
|
|
{
|
|
int q = (int)System::Runtime::InteropServices::Marshal::StringToHGlobalAnsi(sData);
|
|
char* p = (char*)q;
|
|
return std::string(p);
|
|
}
|
|
|
|
//1
|
|
void RecognizerCLR::setRecognitionParams(bool enablePartial) {
|
|
mEnablePartial = enablePartial;
|
|
return;
|
|
}
|
|
|
|
//2
|
|
bool RecognizerCLR::startRecognition(ResultDelegate ^ callback) {
|
|
void* delegatePointer = (void*)Marshal::GetFunctionPointerForDelegate(callback).ToPointer();
|
|
|
|
//bool res =m_pRecognizer->startRecognition(delegatePointer);
|
|
OnlineRecognizerDemo *pRecognizer = new OnlineRecognizerDemo();
|
|
//std::cout << "startRecognition: setRecognitionParams ,mEnablePartial: " << mEnablePartial << std::endl;
|
|
pRecognizer->setRecognitionParams(mEnablePartial);
|
|
bool res = pRecognizer->startRecognition(delegatePointer);
|
|
|
|
return res;
|
|
}
|
|
|
|
/*
|
|
bool RecognizerCLR::startRecognition() {
|
|
|
|
OnlineRecognizerDemo *pRecognizer = new OnlineRecognizerDemo();
|
|
|
|
//std::cout << "startRecognition: setRecognitionParams ,mEnablePartial: " << mEnablePartial<< std::endl;
|
|
pRecognizer->setRecognitionParams(mEnablePartial);
|
|
bool res = pRecognizer->startRecognition();
|
|
//bool res = m_pRecognizer->startRecognition();
|
|
return res;
|
|
}
|
|
*/
|
|
|
|
//3
|
|
void RecognizerCLR::setBeamDir(System::String^ serialPortname, int dir) {
|
|
WWSerialPortApi serialPortTool;
|
|
char* portname = ManagedString2UnmanagedStringA(serialPortname);
|
|
serialPortTool.open(portname);
|
|
serialPortTool.setBeamDir(dir);
|
|
serialPortTool.close();
|
|
}
|
|
|
|
//4
|
|
bool RecognizerCLR::playTts(System::String^ ttsContent, System::String^ language , System::String^ speaker, System::String^ speed) {
|
|
OnlineTtsDemo* ttsDemoPointer = OnlineTtsDemo::GetInstance();
|
|
std::string contentStr = marshal_as<std::string>(ttsContent); //String^ to std
|
|
std::string languageStr = marshal_as<std::string>(language);
|
|
std::string speakerStr = marshal_as<std::string>(speaker);
|
|
std::string speedStr = marshal_as<std::string>(speed);
|
|
ttsDemoPointer->setTtsParas(contentStr, languageStr, speakerStr, speedStr);
|
|
bool res = ttsDemoPointer->Run(0, NULL);
|
|
if (res == true) {
|
|
std::cout << std::endl;
|
|
std::cout << "tts �ɹ�!" << std::endl;
|
|
std::cout << std::endl;
|
|
}
|
|
else {
|
|
std::cout << std::endl;
|
|
std::cout << "tts ʧ��!" << std::endl;
|
|
std::cout << std::endl;
|
|
}
|
|
return res;
|
|
}
|
|
//
|
|
bool RecognizerCLR::playTts() {
|
|
|
|
OnlineTtsDemo* ttsDemoPointer = OnlineTtsDemo::GetInstance();
|
|
bool res = ttsDemoPointer->Run(0, NULL);
|
|
if (res == true) {
|
|
std::cout << std::endl;
|
|
std::cout << "tts �ɹ�!" << std::endl;
|
|
std::cout << std::endl;
|
|
}
|
|
else {
|
|
std::cout << std::endl;
|
|
std::cout << "tts ʧ��!" << std::endl;
|
|
std::cout << std::endl;
|
|
}
|
|
return res;
|
|
}
|
|
|
|
//9 test
|
|
int RecognizerCLR::AddCli(int a, int b)
|
|
{
|
|
//int result = m_pRecognizer->Add(3, 2);
|
|
|
|
//Console::WriteLine(L"Result is {0}", result);
|
|
|
|
//return result;
|
|
return true;
|
|
|
|
}
|
|
|
|
void RecognizerCLR::testDelegate(int number, MessageDelegate^ messageDelegate) {
|
|
|
|
void* delegatePointer = (void*)Marshal::GetFunctionPointerForDelegate(messageDelegate).ToPointer();
|
|
|
|
//m_pRecognizer->WriteMessage(number, delegatePointer);
|
|
|
|
}
|
|
|
|
}
|