遇到的C++ cli 转 C++ native 为C# 程序提供接口。
接口文件
/*++
(do not edit the above line)
********************************************************************************
**
** “INTEL CONFIDENTIAL
** Copyright 2013 - 2018 Intel Corporation All Rights Reserved.
**
********************************************************************************
**
** The source code contained or described herein and all documents related to
** the source code ("Material") are owned by Intel Corporation or its suppliers
** or licensors. Title to the Material remains with Intel Corporation or its
** suppliers and licensors. The Material may contain trade secrets and
** proprietary and confidential information of Intel Corporation and its
** suppliers and licensors, and is protected by worldwide copyright and trade
** secret laws and treaty provisions. No part of the Material may be used,
** copied, reproduced, modified, published, uploaded, posted, transmitted,
** distributed, or disclosed in any way without Intel’s prior express written
** permission.
**
** No license under any patent, copyright, trade secret or other intellectual
** property right is granted to or conferred upon you by disclosure or delivery
** of the Materials, either expressly, by implication, inducement, estoppel or
** otherwise. Any license under such intellectual property rights must be
** express and approved by Intel in writing.
**
** THE MATERIAL IS PROVIDED "AS IS" WITHOUT ANY EXPRESS OR IMPLIED WARRANTY OF
** ANY KIND INCLUDING WARRANTIES OF MERCHANTABILITY, NON-INFRINGEMENT,
** OR FITNESS FOR A PARTICULAR PURPOSE. INTEL WILL NOT PROVIDE ANY SUPPORT,
** ASSISTANCE, INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE
** ANY UPDATES, ENHANCEMENTS OR EXTENSIONS. Intel does not warrant or assume
** responsibility for the accuracy or completeness of any information, text,
** graphics, links or other items contained within the material.
**
** LIMITATION OF LIABILITY. IN NO EVENT SHALL INTEL OR ITS SUPPLIERS BE LIABLE
** FOR ANY DAMAGES WHATSOEVER (INCLUDING, WITHOUT LIMITATION, LOST PROFITS,
** BUSINESS INTERRUPTION, OR LOST INFORMATION) ARISING OUT OF THE USE OF OR
** INABILITY TO USE THE MATERIAL, EVEN IF INTEL HAS BEEN ADVISED OF THE
** POSSIBILITY OF SUCH DAMAGES.
**
** *Third-party brands and names are the property of their respective owners.
**
** Unless otherwise agreed by Intel in writing, you may not remove or alter
** this notice or any other notice embedded in Materials by Intel
** or Intel’s suppliers or licensors in any way.?**
********************************************************************************
--*/
#ifndef _ROCKHOPPER_H_
#define _ROCKHOPPER_H_
#ifdef ROCKHOPPER_LIBRARY_STATIC
# define ROCKHOPPER_API_EXPORT
#else
# ifdef _WIN32
# if defined(ROCKHOPPER_EXPORT) /* Visual Studio */
# define ROCKHOPPER_API_EXPORT __declspec(dllexport)
# elif defined(__CYGWIN__) /* Disable this on Cygwin, it doesn't work */
# define ROCKHOPPER_API_EXPORT
# else
# define ROCKHOPPER_API_EXPORT __declspec(dllimport)
# endif
# else
# if defined(ROCKHOPPER_EXPORT)
# define ROCKHOPPER_API_EXPORT __attribute__((visibility("default")))
# else
# define ROCKHOPPER_API_EXPORT
# endif
# endif
#endif
#ifdef __cplusplus
extern "C" {
#endif
// left for compatibility
#define ROCKHOPPER_SUCCESS RH_NO_ERROR
#define ROCKHOPPER_ERROR RH_ERROR_GENERIC
#define ROCKHOPPER_UNKNOWN_ERROR RH_ERROR_GENERIC
#define ROCKHOPPER_INVALID_PARAMETER RH_ERROR_INVALID_PARAM
#define ROCKHOPPER_INVALID_HANDLE_VALUE RH_ERROR_INVALID_HANDLE_VALUE
#define ROCKHOPPER_INVALID_PATH RH_ERROR_INVALID_PATH
// base error codes
#define RH_NO_ERROR 0
#define RH_ERROR_GENERIC -1
#define RH_ERROR_OUT_OF_MEMORY -2
#define RH_ERROR_FILE_IO -3
#define RH_ERROR_INVALID_RESOURCE -4
#define RH_ERROR_INVALID_PARAM -5
#define RH_ERROR_INVALID_HANDLE_VALUE -6
#define RH_ERROR_INVALID_PATH -7
// Threading error codes
#define RH_ERROR_THREAD_ALREADY_STARTED -10
#define RH_ERROR_THREAD_START_FAILED -11
#define RH_ERROR_THREAD_STOP_FAILED -12
#define RH_ERROR_THREAD_NOT_STARTED -13
// Communication error codes
#define RH_ERROR_OUTPUT_BUFFER_FULL -20
#define RH_ERROR_MESSAGE_ENQUEUE_FAILED -21
// Rest error codes
#define RH_ERROR_MODULE_INIT_FAILED -30
#define RH_ERROR_MODULE_NOT_INITIALIZED -31
#define RH_ERROR_ENGINE_NOT_STARTED -32
#define RH_ERROR_ENGINE_WRONG_STATE -33
#define RH_ERROR_MEMORY_COPY -34
#define RH_ERROR_TOO_SMALL_BUFFER -35
#define RH_ERROR_DATA_OVERWRITTEN -36
#define RH_ERROR_NOT_SUPPORTED -37
// Events
#define ROCKHOPPER_EVENT_ON_READY_FOR_SPEECH 1
#define ROCKHOPPER_EVENT_ON_SPEECH_BEGIN 2
#define ROCKHOPPER_EVENT_ON_SPEECH_END 3
#define ROCKHOPPER_EVENT_ON_RMS_CHANGED 4
#define ROCKHOPPER_EVENT_ON_ERROR 5
#define ROCKHOPPER_EVENT_ENGINE_STARTED 6
#define ROCKHOPPER_EVENT_ENGINE_STOPPED 7
typedef void* ASR_HANDLE; // speech recognition engine handle type
typedef void* WFST_HANDLE; // Handle for a (dynamic) WFST resource
typedef enum RockhopperDataType
{
ROCKHOPPER_DATA_TYPE_SAMPLE_INT_16,
ROCKHOPPER_DATA_TYPE_FEATURE_INT_16
} RockhopperDataType;
/// C-style interface used intentionally to allow for bindings in
/// runtimes that don't support/understand C++ name mangling or
/// reference types
typedef long(*UtteranceCallback)(
void* p, // callback function parameter passed in RockhopperFSSetResultCallback
const short* samples, // Data buffer with utterance samples. Samples are sent only for final result.
// Utterance longer than source buffer length will be passed without samples(null pointer).
int nSamples, // number of samples in buffer
const char* utteranceId, // wall clock time when utterance begins
const char* utteranceText, // recognized text
float score, // recognition score (LM)
int isFinal // 0: partial result, 1: final result (end of utterance)
);
typedef void(*EventCallback)(
void* p, // callback function parameter passed in RockhopperFSSetEventCallback
int eventCode, // event code
int value); // event value
#pragma pack(push, 4)
typedef struct _AsrEngineStatistics {
union {
struct {
unsigned int speech : 1;
unsigned int frontend : 3;
unsigned int scorer : 3;
unsigned int decoder : 3;
unsigned int reserved : 22;
} fields;
int value;
} state;
int signalvl;
int samples_captured_ms;
int frames_extracted_ms;
int frames_decoded_ms;
float uttRtFactor;
int utt_min_snr;
int utt_max_snr;
int utt_snr;
} AsrEngineStatistics;
#pragma pack(pop)
/**
* Initialize the ASR engine component.
*
* @param configurationFilename - absolute path to configuration file the ASR engine shall
* read all its configuration parameters from
* @param resourceDirectory - absolute path to resources listed in config file if relative path used
* @param userResourceDirectory - absolute path to user resources (e.g. dynamic lexicon)
* listed in config file if relative path used
* @param [outptr] asrengine - handle to ASR engine
* @return One of:
* - ROCKHOPPER_SUCCESS (initialization completed successfully),
* - ROCKHOPPER_INVALID_PATH (cannot access the indicated configurationFilename),
* - ROCKHOPPER_UNKNOWN_ERROR (error)
*/
ROCKHOPPER_API_EXPORT int RockhopperFSInitialize(const char* configurationFilename, const char* resourceDirectory,
const char* userResourceDirectory, ASR_HANDLE* asrengine);
/**
* Update dynamic resource from a lexicon and a text acceptor WFST.
*
* @param configurationFilename - absolute path to configuration file the ASR engine shall
* read all its configuration parameters from
* @param resourceDirectory - absolute path of resource data folder (e.g. acoustic model)
* @param userResourceDirectory - absolute path to target folder to contain user generated data
* (e.g. dynamic lexicon)
* @param tagId - ID of meta tag in CL statistical language model the dictionary is "plugged in"
* @param wfst - Grammar wfst used for vocabulary.
*
* @return One of:
* - ROCKHOPPER_SUCCESS (dynamic lexicon update completed successfully),
* - ROCKHOPPER_INVALID_PATH (cannot access the indicated configurationFilename),
* - ROCKHOPPER_UNKNOWN_ERROR (error)
*/
ROCKHOPPER_API_EXPORT int RockhopperFSUpdateDynResource(const char* configurationFilename,
const char* resourceDirectory, const char* userResourceDirectory, int tagId,
WFST_HANDLE wfst);
/**
* Set callback for result processing.
*
* @param [in] asrengine - handle to ASR engine
* @param [in] rescallback - result callback implementation to be invoked once
* utternace or its fragment is recognized
* @param [in] p - callback parameter
* @return One of:
* - ROCKHOPPER_SUCCESS (callback set successfully),
* - ROCKHOPPER_INVALID_HANDLE_VALUE (invalid handle),
* - ROCKHOPPER_UNKNOWN_ERROR (error)
*/
ROCKHOPPER_API_EXPORT int RockhopperFSSetResultCallback(ASR_HANDLE asrengine,
UtteranceCallback callback, const void* p);
/**
* Set callback for events like start / stop engine, ready for speech, speech begin/end, error.
*
* @param [in] asrengine handle to ASR engine
* @param [in] evtcallback - event callback called whenever engine state is changing
* @param [in] p - callback parameter
* @return One of:
* - ROCKHOPPER_SUCCESS (callback set successfully),
* - ROCKHOPPER_INVALID_HANDLE_VALUE (invalid handle),
* - ROCKHOPPER_UNKNOWN_ERROR (error)
*/
ROCKHOPPER_API_EXPORT int RockhopperFSSetEventCallback(ASR_HANDLE asrengine,
EventCallback callback, const void* p);
/**
* Start phrase detection process.
* In response to this method the engine is expected to initialize the
* recognition and continue until a call to stop function is received.
*
* @param [in] asrengine - handle to ASR engine
* @return One of:
* - ROCKHOPPER_SUCCESS (started successfully),
* - ROCKHOPPER_INVALID_HANDLE_VALUE (invalid handle),
* - ROCKHOPPER_UNKNOWN_ERROR (error)
*/
ROCKHOPPER_API_EXPORT int RockhopperFSStartEngine(ASR_HANDLE asrengine);
/**
* Stop Rockhopper engine - resources are not released.
*
* @param [in] asrengine - handle to ASR engine
* @param [in] waitForEndOfUtteranceProcessing - flag:
* True - requests deffered stop, routine does not return till last
* samples/frames in all intermediate buffers are processed
* False - stops immediately if not doing batch file processing
* @return One of:
* - ROCKHOPPER_SUCCESS (stopped successfully),
* - ROCKHOPPER_INVALID_HANDLE_VALUE (invalid handle) ,
* - ROCKHOPPER_UNKNOWN_ERROR (error)
*/
#ifdef __cplusplus
ROCKHOPPER_API_EXPORT int RockhopperFSStopEngine(ASR_HANDLE asrengine, int waitForEndOfUtteranceProcessing = 1);
#else
ROCKHOPPER_API_EXPORT int RockhopperFSStopEngine(ASR_HANDLE asrengine, int waitForEndOfUtteranceProcessing);
#endif
/**
* Release resources of Rockhopper engine.
*
* @param [in] asrengine - handle to ASR engine
* @return One of:
* - ROCKHOPPER_SUCCESS (released successfully),
* - ROCKHOPPER_INVALID_HANDLE_VALUE (invalid handle),
* - ROCKHOPPER_UNKNOWN_ERROR (error)
*/
ROCKHOPPER_API_EXPORT int RockhopperFSReleaseEngine(ASR_HANDLE asrengine);
/**
* Read current Rockhopper state & statistics.
*
* @param [in] asrengine - handle to ASR engine
* @param [inout] stats - pointer to statistics buffer
* @return One of:
* - ROCKHOPPER_SUCCESS (stopped successfully),
* - ROCKHOPPER_INVALID_HANDLE_VALUE (invalid handle),
* - ROCKHOPPER_UNKNOWN_ERROR (error)
*/
ROCKHOPPER_API_EXPORT int RockhopperFSGetStatistics(ASR_HANDLE asrengine, AsrEngineStatistics* stats);
/**
* Feed stream source with samples from external application.
*
* @param [in] asrengine - handle to ASR engine
* @param [in] samples - samples buffer 16kHz mono 16bit resolution
* @param [in] nSamples - number of samples
* @return number of samples consumed by ASR engine ( >=0 ) or STATUS code ( <0 ):
* - ROCKHOPPER_INVALID_HANDLE_VALUE (invalid handle),
* - ROCKHOPPER_UNKNOWN_ERROR (error)
*/
ROCKHOPPER_API_EXPORT int RockhopperFSPushSamples(ASR_HANDLE asrengine, short* samples, int nSamples);
/**
* Feed stream source with data from external application.
*
* @param [in] asrengine - handle to ASR engine
* @param [in] data - pointer to buffer with data to push
* @param [in] elementsCount - number of elements of data, in case of:
* SAMPLE_INT_16 it is the number of samples
* FEATURE_INT_16 it is the number of features
* (must be aligned to features per frame set in config file)
* @param [in] type - type of data to push
* @return number of samples consumed by ASR engine ( >=0 ) or STATUS code ( <0 ):
* - ROCKHOPPER_INVALID_HANDLE_VALUE (invalid handle),
* - ROCKHOPPER_UNKNOWN_ERROR (error)
*/
ROCKHOPPER_API_EXPORT int RockhopperFSPushData(ASR_HANDLE asrengine, void* data,
int elementsCount, RockhopperDataType type);
/**
* Convert grammar specified in JSGF to a WFST
* The WFST is a transducer with input and output labels
*
* @param [in] configurationFilename - absoulute path to configuration file
* the asr engine shall read all it's configuration parameters from
* @param [in] grammar - string buffer representing grammar in JSGF, null terminated
* (http://www.w3.org/TR/2000/NOTE-jsgf-20000605/)
* @param [in] grammarRule - root rule name (if not specified first public rule is selected)
* @param [in] grammarSize - Size of the grammar string buffer including terminating null
* @param [in] grammarRuleSize = Size of the grammarRule buffer including terminating null
* @param [in] firstWordID - Word ID of the first word in the generated WFST.
* It is important that word IDs of different resources do not overlap.
* @param [out] wfst - handle to resulting grammar WFST
*
* @return One of:
* - ROCKHOPPER_SUCCESS (grammar converted successfully),
* - ROCKHOPPER_UNKNOWN_ERROR (error)
*/
ROCKHOPPER_API_EXPORT int RockhopperFSConvertJSGFToFST(const char *configurationFilename,
const char* grammar,
const char* grammarRule,
int grammarSize,
int grammarRuleSize,
int firstWordID,
WFST_HANDLE* wfst);
/**
* Convert ARPA statistical language model into WFST that can be used with
* RockhopperFSUpdateDynResource() to create dynamic recognition resources
*
* @param [in] configurationFilename - absoulute path to configuration file
* the asr engine shall read all it's configuration parameters from
* @param [in] arpa - string buffer representing grammar in ARPA format
* @param [in] arpaSize - Size of the arpa string buffer
* @param [in] firstWordID - Word ID of the first word in the generated WFST.
* It is important that word IDs of different resources do not overlap.
* @param [out] wfst - handle to resulting grammar WFST
*
* @return One of:
* - ROCKHOPPER_SUCCESS (grammar converted successfully),
* - ROCKHOPPER_UNKNOWN_ERROR (error)
*/
ROCKHOPPER_API_EXPORT int RockhopperFSConvertARPAToFST(const char *configurationFilename,
const char* arpa,
int arpaSize,
int firstWordID,
WFST_HANDLE* wfst);
/**
* Convert list of phrases into a Rockhopper WFST that can be used with
* RockhopperFSUpdateDynResource() to create dynamic recognition resources
*
* @param [in] configurationFilename - absoulute path to configuration file
* the asr engine shall read all it's configuration parameters from
* @param [in] phrases - string buffer representing grammar in JSGF
* The different phrases are separated by the newline character '\n'
* @param [in] phrasesSize - Size of the phrases string buffer
* @param [in] firstWordID - Word ID of the first word in the generated WFST.
* It is important that word IDs of different resources do not overlap.
* @param [out] wfst - handle to resulting phrase grammar WFST
*
* @return One of:
* - ROCKHOPPER_SUCCESS (grammar converted successfully),
* - ROCKHOPPER_UNKNOWN_ERROR (error)
*/
ROCKHOPPER_API_EXPORT int RockhopperFSConvertPhrasesToFST(const char* configurationFilename,
const char* phrases,
int phrasesSize,
int firstWordID,
WFST_HANDLE* wfst);
/**
* Convert AT&T (OpenFST) ASCII text representation of a WFST into
* a Rockhopper WFST.
*
* @param [in] configurationFilename - absoulute path to configuration file
* the asr engine shall read all it's configuration parameters from
* @param [in] wfst_text - ASCII representation of the WFST
* @param [in] text_size - Length of wfst_text in bytes
* @param [in] firstWordID - Word ID of the first word in the generated WFST.
* It is important that word IDs of different resources do not overlap.
* @param [out] wfst - Handle to the Rockhopper WFST
*
* @return One of:
* - ROCKHOPPER_SUCCESS (grammar converted successfully),
* - ROCKHOPPER_UNKNOWN_ERROR (error)
*/
ROCKHOPPER_API_EXPORT int RockhopperFSConvertFST(const char *configurationFilename,
const char *wfst_text,
int text_size,
int firstWordID,
WFST_HANDLE* wfst);
/**
* Release (dynamic) WFST resource.
*
* @param [in] wfst - handle to a WFST resource
* @return One of:
* - ROCKHOPPER_SUCCESS (stopped successfully),
* - ROCKHOPPER_INVALID_HANDLE_VALUE (invalid handle),
* - ROCKHOPPER_UNKNOWN_ERROR (error)
*/
ROCKHOPPER_API_EXPORT int RockhopperFSReleaseFST(WFST_HANDLE wfst);
/**
* Get the Rockhopper version string.
*
* @param [out] versionString - pointer to char string with the version ID
* @return One of:
* - ROCKHOPPER_SUCCESS (stopped successfully),
* - ROCKHOPPER_UNKNOWN_ERROR (error)
*/
ROCKHOPPER_API_EXPORT int RockhopperGetVersionString(const char **versionString);
#ifdef __cplusplus
}
#endif
#endif
C++ cli 头文件
#pragmaonce
#include"pch.h"
#include"../SDK/rockhopper.h"
//using namespace System;
#pragmacomment (lib, "../SDK/rockhopper.lib")
namespace IntelSDK {
publicenumclassSDKRockhopperDataType
{
ROCKHOPPER_DATA_TYPE_SAMPLE_INT_16,
ROCKHOPPER_DATA_TYPE_FEATURE_INT_16
};
//[Serializable]
publicrefstructSDKAsrEngineStatistics
{
public:
void setValue(intval)
{
value = val;
}
int getValue()
{
return value;
}
void setSignalvl(intval)
{
signalvl = val;
}
int getSigalvl()
{
return signalvl;
}
void setSamples_captured_ms(intval)
{
samples_captured_ms = val;
}
int gettSamples_captured_ms()
{
return samples_captured_ms;
}
void setFrames_extracted_ms(intval)
{
frames_extracted_ms = val;
}
int getFrames_extracted_ms()
{
return frames_extracted_ms;
}
void setFrames_decoded_ms(intval)
{
frames_decoded_ms = val;
}
int getFrames_decoded_ms()
{
return frames_decoded_ms;
}
void setUttRtFactor(floatval)
{
uttRtFactor = val;
}
float getUttRtFactor()
{
return uttRtFactor;
}
void setUtt_min_snr(intval)
{
utt_min_snr = val;
}
int getUtt_min_snr()
{
return utt_min_snr;
}
void setUtt_max_snr(intval)
{
utt_max_snr = val;
}
int getUtt_max_snr()
{
return utt_max_snr;
}
void setUtt_snr(intval)
{
utt_snr = val;
}
int getUtt_snr()
{
return utt_snr;
}
private:
int value;
int signalvl;
int samples_captured_ms;
int frames_extracted_ms;
int frames_decoded_ms;
float uttRtFactor;
int utt_min_snr;
int utt_max_snr;
int utt_snr;
};
publicdelegatevoiddelegateEventCallback(int eventCode, int value);
publicdelegateintdelegateUtteranceCallback(System::String^ UtteranceText);
publicdelegatelong Delegate_SDKUtteranceCallback(void* p, constshort* samples, int nSamples, constchar* UtteranceId, constchar* UtteranceText, float score, int isFinal);
publicdelegatevoid Delegate_SDKFSSetEventCallback(void* p, int eventCode, int value);
publicrefclassOffLineSDK
{
private:
ASR_HANDLE asrengine = 0;
WFST_HANDLE wfst = 0;
public:
System::String^ getTest(System::String^ name);
OffLineSDK();
~OffLineSDK();
int SDKRockhopperFSStartEngine();
int SDKRockhopperFSStopEngine();
int SDKRockhopperFSInitialize(System::String^ configurationFilename, System::String^ resourceDirectory, System::String^ userResourceDirectory);
int SDKRockhopperFSUpdateDynResource(System::String^ configurationFilename, System::String^ resourceDirectory, System::String^ userResourceDirectory, inttagId);
int SDKRockhopperFSSetResultCallback();
int SDKRockhopperFSReleaseEngine();
int SDKRockhopperFSGetStatistics(SDKAsrEngineStatistics^ stats);
int SDKRockhopperFSPushSamples(array< int>^ samples, intnSamples);
int SDKRockhopperFSConvertJSGFToFST(System::String^ configurationFilename, System::String^ grammar, System::String^ grammarRule, intgrammarSize, intgrammarRuleSize, intfirstWordID);
int SDKRockhopperFSConvertARPAToFST(System::String^ configurationFilename, array<short>^ arpa, intarpaSize, intfirstWordID);
int SDKRockhopperFSPushData(array<short>^ wfst_text, intelementCount, SDKRockhopperDataTypetype);
int SDKRockhopperFSReleaseFST();
int SDKRockhopperFSSetEventCallback();
private:
staticlong SDKUtteranceCallback(void* p, constshort* samples, intnSamples, constchar* UtteranceId, constchar* UtteranceText, floatscore, intisFinal);
staticvoid SDKFSSetEventCallback(void* p, inteventCode, intvalue);
public:
staticeventdelegateEventCallback^ FSSetEventCallback;
staticeventdelegateUtteranceCallback^ EventUtteranceCallback;
};
}
C++ cli 源文件
#include"pch.h"
#include"IntelSDK.h"
#include<string>
#include<iostream>
#include<fstream>
#include<cvt/wstring>
#include<codecvt>
usingnamespace IntelSDK;
#include<msclr\marshal_cppstd.h>
usingnamespace System::Runtime::InteropServices;
constchar* ToCppString(System::String^ s)
{
msclr::interop::marshal_context context;
constchar* result = context.marshal_as<constchar*>(s);
return result;
}
bool To_CharStar(System::String^ source, char*& target)
{
pin_ptr<constwchar_t> wch = PtrToStringChars(source);
int len = ((source->Length + 1) * 2);
target = newchar[len];
return wcstombs(target, wch, len) != -1;
}
bool To_string(System::String^ source, std::string& target)
{
pin_ptr<constwchar_t> wch = PtrToStringChars(source);
int len = ((source->Length + 1) * 2);
char* ch = newchar[len];
bool result = wcstombs(ch, wch, len) != -1;
target= ch;
delete ch;
return result;
}
std::string StringToAscIIChars(System::String^ text)
{
//System::IntPtr ptr=Marshal::SecureStringToGlobalAllocAnsi(text);
std::string converted = msclr::interop::marshal_as<std::string>(text->ToString());
//std::string converted = msclr::interop::marshal_as< std::string >(text);
return converted;
}
std::string StringUtf8ToAscIIChars(System::String^ text) {
std::string converted = msclr::interop::marshal_as< std::string >(text);
return converted;
}
System::String^ UTF8_To_Managed_Str(constchar* chars/*const std::string& str*/)
{
if (chars == nullptr/*|| chars == "" || chars == " " || strnlen_s(chars, INT_MAX) <= 1*/) { // todo what is 0x20
return"";
}
std::string str = std::string(chars);
int nwLen = MultiByteToWideChar(CP_UTF8, 0, str.c_str(), -1, NULL, 0);
wchar_t* pwBuf = newwchar_t[nwLen + 1];
memset(pwBuf, 0, nwLen * 2 + 2);
MultiByteToWideChar(CP_UTF8, 0, str.c_str(), (int)str.length(), pwBuf, nwLen);
System::String^ pStr = gcnew System::String(pwBuf);
delete[] pwBuf;
pwBuf = NULL;
return pStr;
}
System::String^ OffLineSDK::getTest(System::String^ name)
{
//ASR_HANDLE handle = 0;
returnname;
}
OffLineSDK::OffLineSDK()
{
//throw gcnew System::NotImplementedException();
}
OffLineSDK::~OffLineSDK()
{
//throw gcnew System::NotImplementedException();
SDKRockhopperFSReleaseEngine();
SDKRockhopperFSReleaseFST();
}
intOffLineSDK::SDKRockhopperFSStartEngine()
{
/*GCHandle handle = GCHandle::Alloc(objEngine);
System::IntPtr pointer = GCHandle::ToIntPtr(handle);
void* ptr = pointer.ToPointer();*/
//auto ret = RockhopperFSStartEngine(this->ptr);
pin_ptr<ASR_HANDLE> pin = &asrengine;
auto ret = RockhopperFSStartEngine(*pin);
//handle.Free();
return ret;
}
intOffLineSDK::SDKRockhopperFSStopEngine()
{
auto ret = RockhopperFSStopEngine(asrengine);
return ret;
}
int IntelSDK::OffLineSDK::SDKRockhopperFSInitialize(System::String^ configurationFilename, System::String^ resourceDirectory, System::String^ userResourceDirectory)
{
std::string fileName = configurationFilename ? StringToAscIIChars(configurationFilename) : "";
std::string directory = resourceDirectory ? StringToAscIIChars(resourceDirectory) : "";
std::string userDirectory = userResourceDirectory ? StringUtf8ToAscIIChars(userResourceDirectory) : "";
pin_ptr<ASR_HANDLE> pin = &asrengine;
std::cout <<"get some info."<< std::endl;
std::cout << fileName << std::endl;
std::cout << directory << std::endl;
std::cout << userDirectory << std::endl;
// Convert Object^ to void*
/*GCHandle handle = GCHandle::Alloc(objEngine);
System::IntPtr pointer = GCHandle::ToIntPtr(handle);
void* ptr = pointer.ToPointer();
this->ptr = ptr;
ASR_HANDLE asrengine2 = 0;*/
//auto ret = RockhopperFSInitialize("./OffLineConfigFile/rh_params.txt", "./OffLineConfigFile/", "E:\\Code", pin);
//std::string fileName1 = "./OffLineConfigFile/rh_params.txt";
//std::string directory1 = "./OffLineConfigFile/";
//std::string userDirectory1 = "E:\\code";
//
//auto ret = RockhopperFSInitialize(fileName1.c_str(), directory1.c_str(), userDirectory1.c_str(), pin);
auto ret = RockhopperFSInitialize(fileName.c_str(), directory.c_str(), userDirectory.c_str(), pin);
return ret;
}
int IntelSDK::OffLineSDK::SDKRockhopperFSUpdateDynResource(System::String^ configurationFilename, System::String^ resourceDirectory, System::String^ userResourceDirectory, inttagId)
{
std::string fileName = configurationFilename ? StringToAscIIChars(configurationFilename) : "";
std::string rDirectory = resourceDirectory ? StringUtf8ToAscIIChars(resourceDirectory) : "";
std::string userDirectory = userResourceDirectory ? StringUtf8ToAscIIChars(userResourceDirectory) : "";
pin_ptr<WFST_HANDLE> pin = &wfst;
auto ret = RockhopperFSUpdateDynResource(fileName.c_str(), rDirectory.c_str(), userDirectory.c_str(), tagId, pin);
return ret;
}
int IntelSDK::OffLineSDK::SDKRockhopperFSSetResultCallback()
{
Delegate_SDKUtteranceCallback^ fp = gcnewDelegate_SDKUtteranceCallback(SDKUtteranceCallback);
GCHandle gch = GCHandle::Alloc(fp);
System::IntPtr ip = Marshal::GetFunctionPointerForDelegate(fp);
UtteranceCallback cb = static_cast<UtteranceCallback>(ip.ToPointer());
pin_ptr<ASR_HANDLE> pin = &asrengine;
auto ret = RockhopperFSSetResultCallback(*pin, cb, NULL);
return ret;
}
int IntelSDK::OffLineSDK::SDKRockhopperFSReleaseEngine()
{
int res = -1;
pin_ptr<ASR_HANDLE> pin = &asrengine;
if (pin)
{
res = RockhopperFSReleaseEngine(*pin);
}
return res;
}
int IntelSDK::OffLineSDK::SDKRockhopperFSGetStatistics(SDKAsrEngineStatistics^ stats)
{
return 0;
}
int IntelSDK::OffLineSDK::SDKRockhopperFSPushSamples(array<int>^ samples, intnSamples)
{
return 0;
}
int IntelSDK::OffLineSDK::SDKRockhopperFSConvertJSGFToFST(System::String^ configurationFilename, System::String^ grammar, System::String^ grammarRule, intgrammarSize, intgrammarRuleSize, intfirstWordID)
{
return 0;
}
int IntelSDK::OffLineSDK::SDKRockhopperFSConvertARPAToFST(System::String^ configurationFilename, array<short>^ arpa, intarpaSize, intfirstWordID)
{
return 0;
}
int IntelSDK::OffLineSDK::SDKRockhopperFSPushData(array<short>^ wfst_text, intelementCount, SDKRockhopperDataTypetype)
{
if (wfst_text == nullptr)
{
return -3;
}
constint MAX_BUF_SIZE = 20480;
short* sample;
short buff[MAX_BUF_SIZE] = { 0 };
/* if (elementCount > MAX_BUF_SIZE) {
sample = new char[elementCount];
}
else {
sample = buff;
}*/
sample = buff;
for (int i = 0; i < (int)elementCount; i++)
{
sample[i] = wfst_text[i];
}
//RockhopperDataType type= ROCKHOPPER_DATA_TYPE_SAMPLE_INT_16;
/*if (offlinetype == SDKRockhopperDataType::ROCKHOPPER_DATA_TYPE_SAMPLE_INT_16)
{
type = ROCKHOPPER_DATA_TYPE_SAMPLE_INT_16;
}
else
{
type = ROCKHOPPER_DATA_TYPE_FEATURE_INT_16;
}*/
auto ret = RockhopperFSPushData(asrengine, sample, elementCount, ROCKHOPPER_DATA_TYPE_SAMPLE_INT_16);
return ret;
}
int IntelSDK::OffLineSDK::SDKRockhopperFSReleaseFST()
{
auto ret = -1;
if (wfst)
{
ret = RockhopperFSReleaseFST(wfst);
}
return ret;
}
int IntelSDK::OffLineSDK::SDKRockhopperFSSetEventCallback()
{
Delegate_SDKFSSetEventCallback^ fp = gcnewDelegate_SDKFSSetEventCallback(SDKFSSetEventCallback);
GCHandle gch = GCHandle::Alloc(fp);
System::IntPtr ip = Marshal::GetFunctionPointerForDelegate(fp);
EventCallback callBack = static_cast<EventCallback>(ip.ToPointer());
pin_ptr<ASR_HANDLE> pin = &asrengine;
auto res = RockhopperFSSetEventCallback(*pin, callBack, NULL);
return res;
}
long IntelSDK::OffLineSDK::SDKUtteranceCallback(void* p, constshort* samples, intnSamples, constchar* UtteranceId, constchar* UtteranceText, floatscore, intisFinal)
{
auto ret = EventUtteranceCallback(UTF8_To_Managed_Str(UtteranceText));
//return 0;
return ret;
}
void IntelSDK::OffLineSDK::SDKFSSetEventCallback(void* p, inteventCode, intvalue)
{
FSSetEventCallback(eventCode, value);
}
/*++(do not edit the above line)************************************************************************************ “INTEL CONFIDENTIAL** Copyright 2013 - 2018 Intel Corporation All Rights Reserved.************************************************************************************** The source code contained or described herein and all documents related to** the source code ("Material") are owned by Intel Corporation or its suppliers** or licensors. Title to the Material remains with Intel Corporation or its** suppliers and licensors. The Material may contain trade secrets and** proprietary and confidential information of Intel Corporation and its** suppliers and licensors, and is protected by worldwide copyright and trade** secret laws and treaty provisions. No part of the Material may be used,** copied, reproduced, modified, published, uploaded, posted, transmitted,** distributed, or disclosed in any way without Intel’s prior express written** permission.**** No license under any patent, copyright, trade secret or other intellectual** property right is granted to or conferred upon you by disclosure or delivery** of the Materials, either expressly, by implication, inducement, estoppel or** otherwise. Any license under such intellectual property rights must be** express and approved by Intel in writing.**** THE MATERIAL IS PROVIDED "AS IS" WITHOUT ANY EXPRESS OR IMPLIED WARRANTY OF** ANY KIND INCLUDING WARRANTIES OF MERCHANTABILITY, NON-INFRINGEMENT,** OR FITNESS FOR A PARTICULAR PURPOSE. INTEL WILL NOT PROVIDE ANY SUPPORT,** ASSISTANCE, INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE** ANY UPDATES, ENHANCEMENTS OR EXTENSIONS. Intel does not warrant or assume** responsibility for the accuracy or completeness of any information, text,** graphics, links or other items contained within the material.**** LIMITATION OF LIABILITY. IN NO EVENT SHALL INTEL OR ITS SUPPLIERS BE LIABLE** FOR ANY DAMAGES WHATSOEVER (INCLUDING, WITHOUT LIMITATION, LOST PROFITS,** BUSINESS INTERRUPTION, OR LOST INFORMATION) ARISING OUT OF THE USE OF OR** INABILITY TO USE THE MATERIAL, EVEN IF INTEL HAS BEEN ADVISED OF THE** POSSIBILITY OF SUCH DAMAGES.**** *Third-party brands and names are the property of their respective owners.**** Unless otherwise agreed by Intel in writing, you may not remove or alter** this notice or any other notice embedded in Materials by Intel** or Intel’s suppliers or licensors in any way.?**********************************************************************************--*/
#ifndef _ROCKHOPPER_H_#define _ROCKHOPPER_H_
#ifdef ROCKHOPPER_LIBRARY_STATIC# define ROCKHOPPER_API_EXPORT#else# ifdef _WIN32# if defined(ROCKHOPPER_EXPORT) /* Visual Studio */# define ROCKHOPPER_API_EXPORT __declspec(dllexport)# elif defined(__CYGWIN__) /* Disable this on Cygwin, it doesn't work */# define ROCKHOPPER_API_EXPORT# else# define ROCKHOPPER_API_EXPORT __declspec(dllimport)# endif# else# if defined(ROCKHOPPER_EXPORT)# define ROCKHOPPER_API_EXPORT __attribute__((visibility("default")))# else# define ROCKHOPPER_API_EXPORT# endif# endif#endif
#ifdef __cplusplusextern "C" {#endif
// left for compatibility #define ROCKHOPPER_SUCCESS RH_NO_ERROR #define ROCKHOPPER_ERROR RH_ERROR_GENERIC #define ROCKHOPPER_UNKNOWN_ERROR RH_ERROR_GENERIC #define ROCKHOPPER_INVALID_PARAMETER RH_ERROR_INVALID_PARAM #define ROCKHOPPER_INVALID_HANDLE_VALUE RH_ERROR_INVALID_HANDLE_VALUE #define ROCKHOPPER_INVALID_PATH RH_ERROR_INVALID_PATH
// base error codes #define RH_NO_ERROR 0 #define RH_ERROR_GENERIC -1 #define RH_ERROR_OUT_OF_MEMORY -2 #define RH_ERROR_FILE_IO -3 #define RH_ERROR_INVALID_RESOURCE -4 #define RH_ERROR_INVALID_PARAM -5 #define RH_ERROR_INVALID_HANDLE_VALUE -6 #define RH_ERROR_INVALID_PATH -7
// Threading error codes #define RH_ERROR_THREAD_ALREADY_STARTED -10 #define RH_ERROR_THREAD_START_FAILED -11 #define RH_ERROR_THREAD_STOP_FAILED -12 #define RH_ERROR_THREAD_NOT_STARTED -13
// Communication error codes #define RH_ERROR_OUTPUT_BUFFER_FULL -20 #define RH_ERROR_MESSAGE_ENQUEUE_FAILED -21
// Rest error codes #define RH_ERROR_MODULE_INIT_FAILED -30 #define RH_ERROR_MODULE_NOT_INITIALIZED -31 #define RH_ERROR_ENGINE_NOT_STARTED -32 #define RH_ERROR_ENGINE_WRONG_STATE -33 #define RH_ERROR_MEMORY_COPY -34 #define RH_ERROR_TOO_SMALL_BUFFER -35 #define RH_ERROR_DATA_OVERWRITTEN -36 #define RH_ERROR_NOT_SUPPORTED -37
// Events #define ROCKHOPPER_EVENT_ON_READY_FOR_SPEECH 1 #define ROCKHOPPER_EVENT_ON_SPEECH_BEGIN 2 #define ROCKHOPPER_EVENT_ON_SPEECH_END 3 #define ROCKHOPPER_EVENT_ON_RMS_CHANGED 4 #define ROCKHOPPER_EVENT_ON_ERROR 5 #define ROCKHOPPER_EVENT_ENGINE_STARTED 6 #define ROCKHOPPER_EVENT_ENGINE_STOPPED 7
typedef void* ASR_HANDLE; // speech recognition engine handle type typedef void* WFST_HANDLE; // Handle for a (dynamic) WFST resource
typedef enum RockhopperDataType { ROCKHOPPER_DATA_TYPE_SAMPLE_INT_16, ROCKHOPPER_DATA_TYPE_FEATURE_INT_16 } RockhopperDataType;
/// C-style interface used intentionally to allow for bindings in /// runtimes that don't support/understand C++ name mangling or /// reference types
typedef long(*UtteranceCallback)( void* p, // callback function parameter passed in RockhopperFSSetResultCallback const short* samples, // Data buffer with utterance samples. Samples are sent only for final result. // Utterance longer than source buffer length will be passed without samples(null pointer). int nSamples, // number of samples in buffer const char* utteranceId, // wall clock time when utterance begins const char* utteranceText, // recognized text float score, // recognition score (LM) int isFinal // 0: partial result, 1: final result (end of utterance) );
typedef void(*EventCallback)( void* p, // callback function parameter passed in RockhopperFSSetEventCallback int eventCode, // event code int value); // event value
#pragma pack(push, 4) typedef struct _AsrEngineStatistics { union { struct { unsigned int speech : 1; unsigned int frontend : 3; unsigned int scorer : 3; unsigned int decoder : 3; unsigned int reserved : 22; } fields; int value; } state; int signalvl; int samples_captured_ms; int frames_extracted_ms; int frames_decoded_ms; float uttRtFactor; int utt_min_snr; int utt_max_snr; int utt_snr; } AsrEngineStatistics;
#pragma pack(pop) /** * Initialize the ASR engine component. * * @param configurationFilename - absolute path to configuration file the ASR engine shall * read all its configuration parameters from * @param resourceDirectory - absolute path to resources listed in config file if relative path used * @param userResourceDirectory - absolute path to user resources (e.g. dynamic lexicon) * listed in config file if relative path used * @param [outptr] asrengine - handle to ASR engine * @return One of: * - ROCKHOPPER_SUCCESS (initialization completed successfully), * - ROCKHOPPER_INVALID_PATH (cannot access the indicated configurationFilename), * - ROCKHOPPER_UNKNOWN_ERROR (error) */ ROCKHOPPER_API_EXPORT int RockhopperFSInitialize(const char* configurationFilename, const char* resourceDirectory, const char* userResourceDirectory, ASR_HANDLE* asrengine);
/** * Update dynamic resource from a lexicon and a text acceptor WFST. * * @param configurationFilename - absolute path to configuration file the ASR engine shall * read all its configuration parameters from * @param resourceDirectory - absolute path of resource data folder (e.g. acoustic model) * @param userResourceDirectory - absolute path to target folder to contain user generated data * (e.g. dynamic lexicon) * @param tagId - ID of meta tag in CL statistical language model the dictionary is "plugged in" * @param wfst - Grammar wfst used for vocabulary. * * @return One of: * - ROCKHOPPER_SUCCESS (dynamic lexicon update completed successfully), * - ROCKHOPPER_INVALID_PATH (cannot access the indicated configurationFilename), * - ROCKHOPPER_UNKNOWN_ERROR (error) */ ROCKHOPPER_API_EXPORT int RockhopperFSUpdateDynResource(const char* configurationFilename, const char* resourceDirectory, const char* userResourceDirectory, int tagId, WFST_HANDLE wfst);
/** * Set callback for result processing. * * @param [in] asrengine - handle to ASR engine * @param [in] rescallback - result callback implementation to be invoked once * utternace or its fragment is recognized * @param [in] p - callback parameter * @return One of: * - ROCKHOPPER_SUCCESS (callback set successfully), * - ROCKHOPPER_INVALID_HANDLE_VALUE (invalid handle), * - ROCKHOPPER_UNKNOWN_ERROR (error) */ ROCKHOPPER_API_EXPORT int RockhopperFSSetResultCallback(ASR_HANDLE asrengine, UtteranceCallback callback, const void* p);
/** * Set callback for events like start / stop engine, ready for speech, speech begin/end, error. * * @param [in] asrengine handle to ASR engine * @param [in] evtcallback - event callback called whenever engine state is changing * @param [in] p - callback parameter * @return One of: * - ROCKHOPPER_SUCCESS (callback set successfully), * - ROCKHOPPER_INVALID_HANDLE_VALUE (invalid handle), * - ROCKHOPPER_UNKNOWN_ERROR (error) */ ROCKHOPPER_API_EXPORT int RockhopperFSSetEventCallback(ASR_HANDLE asrengine, EventCallback callback, const void* p);
/** * Start phrase detection process. * In response to this method the engine is expected to initialize the * recognition and continue until a call to stop function is received. * * @param [in] asrengine - handle to ASR engine * @return One of: * - ROCKHOPPER_SUCCESS (started successfully), * - ROCKHOPPER_INVALID_HANDLE_VALUE (invalid handle), * - ROCKHOPPER_UNKNOWN_ERROR (error) */ ROCKHOPPER_API_EXPORT int RockhopperFSStartEngine(ASR_HANDLE asrengine);
/** * Stop Rockhopper engine - resources are not released. * * @param [in] asrengine - handle to ASR engine * @param [in] waitForEndOfUtteranceProcessing - flag: * True - requests deffered stop, routine does not return till last * samples/frames in all intermediate buffers are processed * False - stops immediately if not doing batch file processing * @return One of: * - ROCKHOPPER_SUCCESS (stopped successfully), * - ROCKHOPPER_INVALID_HANDLE_VALUE (invalid handle) , * - ROCKHOPPER_UNKNOWN_ERROR (error) */#ifdef __cplusplus ROCKHOPPER_API_EXPORT int RockhopperFSStopEngine(ASR_HANDLE asrengine, int waitForEndOfUtteranceProcessing = 1);#else ROCKHOPPER_API_EXPORT int RockhopperFSStopEngine(ASR_HANDLE asrengine, int waitForEndOfUtteranceProcessing);#endif
/** * Release resources of Rockhopper engine. * * @param [in] asrengine - handle to ASR engine * @return One of: * - ROCKHOPPER_SUCCESS (released successfully), * - ROCKHOPPER_INVALID_HANDLE_VALUE (invalid handle), * - ROCKHOPPER_UNKNOWN_ERROR (error) */ ROCKHOPPER_API_EXPORT int RockhopperFSReleaseEngine(ASR_HANDLE asrengine);
/** * Read current Rockhopper state & statistics. * * @param [in] asrengine - handle to ASR engine * @param [inout] stats - pointer to statistics buffer * @return One of: * - ROCKHOPPER_SUCCESS (stopped successfully), * - ROCKHOPPER_INVALID_HANDLE_VALUE (invalid handle), * - ROCKHOPPER_UNKNOWN_ERROR (error) */ ROCKHOPPER_API_EXPORT int RockhopperFSGetStatistics(ASR_HANDLE asrengine, AsrEngineStatistics* stats);
/** * Feed stream source with samples from external application. * * @param [in] asrengine - handle to ASR engine * @param [in] samples - samples buffer 16kHz mono 16bit resolution * @param [in] nSamples - number of samples * @return number of samples consumed by ASR engine ( >=0 ) or STATUS code ( <0 ): * - ROCKHOPPER_INVALID_HANDLE_VALUE (invalid handle), * - ROCKHOPPER_UNKNOWN_ERROR (error) */ ROCKHOPPER_API_EXPORT int RockhopperFSPushSamples(ASR_HANDLE asrengine, short* samples, int nSamples);
/** * Feed stream source with data from external application. * * @param [in] asrengine - handle to ASR engine * @param [in] data - pointer to buffer with data to push * @param [in] elementsCount - number of elements of data, in case of: * SAMPLE_INT_16 it is the number of samples * FEATURE_INT_16 it is the number of features * (must be aligned to features per frame set in config file) * @param [in] type - type of data to push * @return number of samples consumed by ASR engine ( >=0 ) or STATUS code ( <0 ): * - ROCKHOPPER_INVALID_HANDLE_VALUE (invalid handle), * - ROCKHOPPER_UNKNOWN_ERROR (error) */ ROCKHOPPER_API_EXPORT int RockhopperFSPushData(ASR_HANDLE asrengine, void* data, int elementsCount, RockhopperDataType type);
/** * Convert grammar specified in JSGF to a WFST * The WFST is a transducer with input and output labels * * @param [in] configurationFilename - absoulute path to configuration file * the asr engine shall read all it's configuration parameters from * @param [in] grammar - string buffer representing grammar in JSGF, null terminated * (http://www.w3.org/TR/2000/NOTE-jsgf-20000605/) * @param [in] grammarRule - root rule name (if not specified first public rule is selected) * @param [in] grammarSize - Size of the grammar string buffer including terminating null * @param [in] grammarRuleSize = Size of the grammarRule buffer including terminating null * @param [in] firstWordID - Word ID of the first word in the generated WFST. * It is important that word IDs of different resources do not overlap. * @param [out] wfst - handle to resulting grammar WFST * * @return One of: * - ROCKHOPPER_SUCCESS (grammar converted successfully), * - ROCKHOPPER_UNKNOWN_ERROR (error) */ ROCKHOPPER_API_EXPORT int RockhopperFSConvertJSGFToFST(const char *configurationFilename, const char* grammar, const char* grammarRule, int grammarSize, int grammarRuleSize, int firstWordID, WFST_HANDLE* wfst);
/** * Convert ARPA statistical language model into WFST that can be used with * RockhopperFSUpdateDynResource() to create dynamic recognition resources * * @param [in] configurationFilename - absoulute path to configuration file * the asr engine shall read all it's configuration parameters from * @param [in] arpa - string buffer representing grammar in ARPA format * @param [in] arpaSize - Size of the arpa string buffer * @param [in] firstWordID - Word ID of the first word in the generated WFST. * It is important that word IDs of different resources do not overlap. * @param [out] wfst - handle to resulting grammar WFST * * @return One of: * - ROCKHOPPER_SUCCESS (grammar converted successfully), * - ROCKHOPPER_UNKNOWN_ERROR (error) */ ROCKHOPPER_API_EXPORT int RockhopperFSConvertARPAToFST(const char *configurationFilename, const char* arpa, int arpaSize, int firstWordID, WFST_HANDLE* wfst);
/** * Convert list of phrases into a Rockhopper WFST that can be used with * RockhopperFSUpdateDynResource() to create dynamic recognition resources * * @param [in] configurationFilename - absoulute path to configuration file * the asr engine shall read all it's configuration parameters from * @param [in] phrases - string buffer representing grammar in JSGF * The different phrases are separated by the newline character '\n' * @param [in] phrasesSize - Size of the phrases string buffer * @param [in] firstWordID - Word ID of the first word in the generated WFST. * It is important that word IDs of different resources do not overlap. * @param [out] wfst - handle to resulting phrase grammar WFST * * @return One of: * - ROCKHOPPER_SUCCESS (grammar converted successfully), * - ROCKHOPPER_UNKNOWN_ERROR (error) */ ROCKHOPPER_API_EXPORT int RockhopperFSConvertPhrasesToFST(const char* configurationFilename, const char* phrases, int phrasesSize, int firstWordID, WFST_HANDLE* wfst);
/** * Convert AT&T (OpenFST) ASCII text representation of a WFST into * a Rockhopper WFST. * * @param [in] configurationFilename - absoulute path to configuration file * the asr engine shall read all it's configuration parameters from * @param [in] wfst_text - ASCII representation of the WFST * @param [in] text_size - Length of wfst_text in bytes * @param [in] firstWordID - Word ID of the first word in the generated WFST. * It is important that word IDs of different resources do not overlap. * @param [out] wfst - Handle to the Rockhopper WFST * * @return One of: * - ROCKHOPPER_SUCCESS (grammar converted successfully), * - ROCKHOPPER_UNKNOWN_ERROR (error) */ ROCKHOPPER_API_EXPORT int RockhopperFSConvertFST(const char *configurationFilename, const char *wfst_text, int text_size, int firstWordID, WFST_HANDLE* wfst);
/** * Release (dynamic) WFST resource. * * @param [in] wfst - handle to a WFST resource * @return One of: * - ROCKHOPPER_SUCCESS (stopped successfully), * - ROCKHOPPER_INVALID_HANDLE_VALUE (invalid handle), * - ROCKHOPPER_UNKNOWN_ERROR (error) */ ROCKHOPPER_API_EXPORT int RockhopperFSReleaseFST(WFST_HANDLE wfst);
/** * Get the Rockhopper version string. * * @param [out] versionString - pointer to char string with the version ID * @return One of: * - ROCKHOPPER_SUCCESS (stopped successfully), * - ROCKHOPPER_UNKNOWN_ERROR (error) */ ROCKHOPPER_API_EXPORT int RockhopperGetVersionString(const char **versionString);
#ifdef __cplusplus}#endif#endif
遇到的C++ cli 转 C++ native 为C# 程序提供接口。的更多相关文章
- 使用GDB调试Android NDK native(C/C++)程序
使用GDB调试Android NDK native(C/C++)程序 先说明下,这里所谓的ndk native程序跟Android上层java应用没有什么关系,也不需要涉及jni来封装native接口 ...
- 纠结的CLI C++与Native C++的交互
最近在写点东西,涉及到了CLR C++与Native C++的互相调用的问题,结果...........纠结啊. 交互原型 交互原型是这样的: void* avio_alloc_context( un ...
- C++ / CLI 调用 C++ /Native 随记
C# 封装 原生C++ 方法:1.C++ CLR(托管) 调用 C++(原生)2.C#调用C++ CLR , 注意各个平台编译版本需一致.3.C# 默认编绎生成版本是 any cpu , 需修改成 ...
- 尝试在mac上用dotnet cli运行asp.net core示例程序
自从知道微软用dotnet cli取代dnx之后,一直在等dotnet cli支持asp.net core... 昨天看到这篇新闻(ASP.NET Core 1.0 Hello World)后,才知道 ...
- (用微信扫的静态链接二维码)微信native支付模式官方提供的demo文件中的几个bug修正
native支付模式一demo(用微信扫的静态链接二维码)BUG修复,一共4个BUG 1.native_call_qrcode.php这个文件中的代码无法生存native支付的短地址2.WxPayPu ...
- 使用GDB调试Android NDK native(C/C++)程序-转
最 近写了些需要跨平台兼容的C++库,Android是其中需要兼容的平台之一.区别于Windows,Mac中功能强大的IDE环境,官方并没有为 Android ndk提供太多的支持.因此,尝试了下通过 ...
- 一个关于native sql的程序
*&---------------------------------------------------------------------* *& Report ZHR_BPM11 ...
- CPF 使用C#的Native AOT 发布程序
微软已经将AOT的包移到Nuget了,之前是在实验测试服务器上的.并且由之前的alpha版本改成了preview版本. C#的开发效率,接近C++的运行效率,而且可以防止反编译,可以支持大部分反射功能 ...
- 【转】高通平台android 环境配置编译及开发经验总结
原文网址:http://blog.csdn.net/dongwuming/article/details/12784535 1.高通平台android开发总结 1.1 搭建高通平台环境开发环境 在高通 ...
随机推荐
- 【记录】如何造一个vite插件(1)
在看文章前,先做个定位,这不是一篇纯粹的技术性文章,可以把它理解成一个叙述文章,记录我开发插件的过程. 开始前简单的吹个牛 vue2 也写了很多年了,多人合作始终避不开用到别人的组件.关键是有些组件没 ...
- Maven多模块Spring的注入
第一次做多模块项目,Unit Test的时候发现Biz模块没法注入Dal模块的Mappper,提示找不到Bean. POM文件是正确引入了dependency的,扫描的package也没错,所以卡了好 ...
- 深入理解JavaScript中的继承
1前言 继承是JavaScript中的重要概念,可以说要学好JavaScript,必须搞清楚JavaScript中的继承.我最开始是通过看视频听培训班的老师讲解的JavaScript中的继承,当时看的 ...
- 关于java.lang.IllegalMonitorStateException异常说明(四)
1.异常原因及解释 首先你要了解这个异常为什么会抛出,这个异常会在三种情况下抛出:1>当前线程不含有当前对象的锁资源的时候,调用obj.wait()方法;2>当前线程不含有当前对象的锁资源 ...
- 浅谈树模型与集成学习-从决策树到GBDT
引言 神经网络模型,特别是深度神经网络模型,自AlexNet在Imagenet Challenge 2012上的一鸣惊人,无疑是Machine Learning Research上最靓的仔,各种进 ...
- 构建后端第2篇之---springb @ComponentScan注解使用
张艳涛写于2021-2-8日 构建后端项目的时候遇到一个问题,在zyt-auth项目的依赖定义了@Component类,这个类在项目启动的时候提示没有找到bean Field tokenService ...
- 「必知必会」最细致的 LinkedList 原理分析
1.结构 1. 继承 该类继承自 AbstractSequentialList 这个是由于他是一个顺序的列表,所以说继承的是一个顺序的 List 2. 实现 这个类实现的接口比较多,具体如下: 首 ...
- CTF_论剑场_Web20
直接上脚本,多跑几次就能出flag import requests import re url = "http://123.206.31.85:10020/" s = reques ...
- postman之变量
前言:postman可以设置(环境变量)和(全局变量) (环境变量):环境变量只能在选择的环境中使用,可以有多组,常用在设置URL和密码当中 (全局变量):只能有一组,整个环境都可以应用 [环境变量] ...
- 【Lua篇】静态代码扫描分析(一)初步介绍
一.静态代码分析 静态代码分析是一种通过检查代码而不是执行程序来发现源代码中错误的手段.通常可以帮助我们发现常见的编码错误,例如: 语法错误 违反制定的标准编码 未定义的变量 安全性问 ...