qisr.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. /**
  2. * @file qisr.h
  3. * @brief iFLY Speech Recognizer Header File
  4. *
  5. * This file contains the quick application programming interface (API) declarations
  6. * of ISR. Developer can include this file in your project to build applications.
  7. * For more information, please read the developer guide.
  8. * Use of this software is subject to certain restrictions and limitations set
  9. * forth in a license agreement entered into between iFLYTEK, Co,LTD.
  10. * and the licensee of this software. Please refer to the license
  11. * agreement for license use rights and restrictions.
  12. *
  13. * Copyright (C) 1999 - 2007 by ANHUI USTC iFLYTEK, Co,LTD.
  14. * All rights reserved.
  15. *
  16. * @author Speech Dept. iFLYTEK.
  17. * @version 1.0
  18. * @date 2008/12/12
  19. *
  20. * @see
  21. *
  22. * History:
  23. * index version date author notes
  24. * 0 1.0 2008/12/12 Speech Create this file
  25. */
  26. #ifndef __QISR_H__
  27. #define __QISR_H__
  28. #ifdef __cplusplus
  29. extern "C" {
  30. #endif /* C++ */
  31. #include "msp_types.h"
  32. /**
  33. * @fn QISRSessionBegin
  34. * @brief Begin a Recognizer Session
  35. *
  36. * Create a recognizer session to recognize audio data
  37. *
  38. * @return return sessionID of current session, NULL is failed.
  39. * @param const char* grammarList - [in] grammars list, inline grammar support only one.
  40. * @param const char* params - [in] parameters when the session created.
  41. * @param int *errorCode - [out] return 0 on success, otherwise return error code.
  42. * @see
  43. */
  44. const char* MSPAPI QISRSessionBegin(const char* grammarList, const char* params, int* errorCode);
  45. typedef const char* (MSPAPI *Proc_QISRSessionBegin)(const char* grammarList, const char* params, int *result);
  46. #ifdef MSP_WCHAR_SUPPORT
  47. const wchar_t* MSPAPI QISRSessionBeginW(const wchar_t* grammarList, const wchar_t* params, int *result);
  48. typedef const wchar_t* (MSPAPI *Proc_QISRSessionBeginW)(const wchar_t* grammarList, const wchar_t* params, int *result);
  49. #endif
  50. /**
  51. * @fn QISRAudioWrite
  52. * @brief Write Audio Data to Recognizer Session
  53. *
  54. * Writing binary audio data to recognizer.
  55. *
  56. * @return int MSPAPI - Return 0 in success, otherwise return error code.
  57. * @param const char* sessionID - [in] The session id returned by recog_begin
  58. * @param const void* waveData - [in] Binary data of waveform
  59. * @param unsigned int waveLen - [in] Waveform data size in bytes
  60. * @param int audioStatus - [in] Audio status, can be
  61. * @param int *epStatus - [out] ISRepState
  62. * @param int *recogStatus - [out] ISRrecRecognizerStatus, see isr_rec.h
  63. * @see
  64. */
  65. int MSPAPI QISRAudioWrite(const char* sessionID, const void* waveData, unsigned int waveLen, int audioStatus, int *epStatus, int *recogStatus);
  66. typedef int (MSPAPI *Proc_QISRAudioWrite)(const char* sessionID, const void* waveData, unsigned int waveLen, int audioStatus, int *epStatus, int *recogStatus);
  67. #ifdef MSP_WCHAR_SUPPORT
  68. int MSPAPI QISRAudioWriteW(const wchar_t* sessionID, const void* waveData, unsigned int waveLen, int audioStatus, int *epStatus, int *recogStatus);
  69. typedef int (MSPAPI *Proc_QISRAudioWriteW)(const wchar_t* sessionID, const void* waveData, unsigned int waveLen, int audioStatus, int *epStatus, int *recogStatus);
  70. #endif
  71. /**
  72. * @fn QISRGetResult
  73. * @brief Get Recognize Result in Specified Format
  74. *
  75. * Get recognize result in Specified format.
  76. *
  77. * @return int MSPAPI - Return 0 in success, otherwise return error code.
  78. * @param const char* sessionID - [in] session id returned by session begin
  79. * @param int* rsltStatus - [out] status of recognition result, 0: success, 1: no match, 2: incomplete, 5:speech complete
  80. * @param int *errorCode - [out] return 0 on success, otherwise return error code.
  81. * @see
  82. */
  83. const char * MSPAPI QISRGetResult(const char* sessionID, int* rsltStatus, int waitTime, int *errorCode);
  84. typedef const char * (MSPAPI *Proc_QISRGetResult)(const char* sessionID, int* rsltStatus, int waitTime, int *errorCode);
  85. #ifdef MSP_WCHAR_SUPPORT
  86. const wchar_t* MSPAPI QISRGetResultW(const wchar_t* sessionID, int* rsltStatus, int waitTime, int *errorCode);
  87. typedef const wchar_t* (MSPAPI *Proc_QISRGetResultW)(const wchar_t* sessionID, int* rsltStatus, int waitTime, int *errorCode);
  88. #endif
  89. /**
  90. * @fn QISRGetBinaryResult
  91. * @brief Get Recognize Result in Specified Format
  92. *
  93. * Get recognize result in Specified format.
  94. *
  95. * @return int MSPAPI - Return 0 in success, otherwise return error code.
  96. * @param const char* sessionID - [in] session id returned by session begin
  97. * @param int* rsltStatus - [out] status of recognition result, 0: success, 1: no match, 2: incomplete, 5:speech complete
  98. * @param int *errorCode - [out] return 0 on success, otherwise return error code.
  99. * @see
  100. */
  101. const char * MSPAPI QISRGetBinaryResult(const char* sessionID, unsigned int* rsltLen,int* rsltStatus, int waitTime, int *errorCode);
  102. typedef const char * (MSPAPI *Proc_QISRGetBinaryResult)(const char* sessionID, unsigned int* rsltLen, int* rsltStatus, int waitTime, int *errorCode);
  103. #ifdef MSP_WCHAR_SUPPORT
  104. const wchar_t* MSPAPI QISRGetBinaryResultW(const wchar_t* sessionID, unsigned int* rsltLen, int* rsltStatus, int waitTime, int *errorCode);
  105. typedef const wchar_t* (MSPAPI *Proc_QISRGetBinaryResultW)(const wchar_t* sessionID, unsigned int* rsltLen, int* rsltStatus, int waitTime, int *errorCode);
  106. #endif
  107. /**
  108. * @fn QISRSessionEnd
  109. * @brief End a Recognizer Session
  110. *
  111. * End the recognizer session, release all resource.
  112. *
  113. * @return int MSPAPI - Return 0 in success, otherwise return error code.
  114. * @param const char* sessionID - [in] session id string to end
  115. * @param const char* hints - [in] user hints to end session, hints will be logged to CallLog
  116. * @see
  117. */
  118. int MSPAPI QISRSessionEnd(const char* sessionID, const char* hints);
  119. typedef int (MSPAPI *Proc_QISRSessionEnd)(const char* sessionID, const char* hints);
  120. #ifdef MSP_WCHAR_SUPPORT
  121. int MSPAPI QISRSessionEndW(const wchar_t* sessionID, const wchar_t* hints);
  122. typedef int (MSPAPI *Proc_QISRSessionEndW)(const wchar_t* sessionID, const wchar_t* hints);
  123. #endif
  124. /**
  125. * @fn QISRGetParam
  126. * @brief get params related with msc
  127. *
  128. * the params could be local or server param, we only support netflow params "upflow" & "downflow" now
  129. *
  130. * @return int - Return 0 if success, otherwise return errcode.
  131. * @param const char* sessionID - [in] session id of related param, set NULL to got global param
  132. * @param const char* paramName - [in] param name,could pass more than one param split by ','';'or'\n'
  133. * @param const char* paramValue - [in] param value buffer, malloced by user
  134. * @param int *valueLen - [in, out] pass in length of value buffer, and return length of value string
  135. * @see
  136. */
  137. int MSPAPI QISRGetParam(const char* sessionID, const char* paramName, char* paramValue, unsigned int* valueLen);
  138. typedef int (MSPAPI *Proc_QISRGetParam)(const char* sessionID, const char* paramName, char* paramValue, unsigned int* valueLen);
  139. #ifdef MSP_WCHAR_SUPPORT
  140. int MSPAPI QISRGetParamW(const wchar_t* sessionID, const wchar_t* paramName, wchar_t* paramValue, unsigned int* valueLen);
  141. typedef int (MSPAPI *Proc_QISRGetParamW)(const wchar_t* sessionID, const wchar_t* paramName, wchar_t* paramValue, unsigned int* valueLen);
  142. #endif
  143. /**
  144. * @fn QISRSetParam
  145. * @brief get params related with msc
  146. *
  147. * the params could be local or server param, we only support netflow params "upflow" & "downflow" now
  148. *
  149. * @return int - Return 0 if success, otherwise return errcode.
  150. * @param const char* sessionID - [in] session id of related param, set NULL to got global param
  151. * @param const char* paramName - [in] param name,could pass more than one param split by ','';'or'\n'
  152. * @param const char* paramValue - [in] param value buffer, malloced by user
  153. * @param int *valueLen - [in, out] pass in length of value buffer, and return length of value string
  154. * @see
  155. */
  156. int MSPAPI QISRSetParam(const char* sessionID, const char* paramName, const char* paramValue);
  157. typedef int (MSPAPI *Proc_QISRSetParam)(const char* sessionID, const char* paramName, const char* paramValue);
  158. #ifdef MSP_WCHAR_SUPPORT
  159. int MSPAPI QISRSetParamW(const wchar_t* sessionID, const wchar_t* paramName, const wchar_t* paramValue);
  160. typedef int (MSPAPI *Proc_QISRSetParamW)(const wchar_t* sessionID, const wchar_t* paramName, const wchar_t* paramValue);
  161. #endif
  162. typedef void ( *recog_result_ntf_handler)( const char *sessionID, const char *result, int resultLen, int resultStatus, void *userData );
  163. typedef void ( *recog_status_ntf_handler)( const char *sessionID, int type, int status, int param1, const void *param2, void *userData);
  164. typedef void ( *recog_error_ntf_handler)(const char *sessionID, int errorCode, const char *detail, void *userData);
  165. int MSPAPI QISRRegisterNotify(const char *sessionID, recog_result_ntf_handler rsltCb, recog_status_ntf_handler statusCb, recog_error_ntf_handler errCb, void *userData);
  166. typedef int ( *UserCallBack)( int, const char*, void*);
  167. typedef int ( *GrammarCallBack)( int, const char*, void*);
  168. typedef int ( *LexiconCallBack)( int, const char*, void*);
  169. int MSPAPI QISRBuildGrammar(const char *grammarType, const char *grammarContent, unsigned int grammarLength, const char *params, GrammarCallBack callback, void *userData);
  170. typedef int (MSPAPI *Proc_QISRBuildGrammar)(const char *grammarType, const char *grammarContent, unsigned int grammarLength, const char *params, GrammarCallBack callback, void *userData);
  171. #ifdef MSP_WCHAR_SUPPORT
  172. int MSPAPI QISRBuildGrammarW(const wchar_t *grmmarType, const wchar_t *grammarContent, unsigned int grammarLength, const wchar_t *params, GrammarCallBack callback, void *userData);
  173. typedef int (MSPAPI *Proc_QISRBuildGrammarW)(const wchar_t *grmmarType, const wchar_t *grammarContent, unsigned int grammarLength, const wchar_t *params, GrammarCallBack callback, void *userData);
  174. #endif
  175. int MSPAPI QISRUpdateLexicon(const char *lexiconName, const char *lexiconContent, unsigned int lexiconLength, const char *params, LexiconCallBack callback, void *userData);
  176. typedef int (MSPAPI *Proc_QISRUpdataLexicon)(const char *lexiconName, const char *lexiconContent, unsigned int lexiconLength, const char *params, LexiconCallBack callback, void *userData);
  177. #ifdef MSP_WCHAR_SUPPORT
  178. int MSPAPI QISRUpdateLexiconW(const wchar_t *lexiconName, const wchar_t *lexiconContent, unsigned int lexiconLength, const wchar_t *params, LexiconCallBack callback, void *userData);
  179. typedef int (MSPAPI Proc_QISRUpdateLexiconW)(const wchar_t *lexiconName, const wchar_t *lexiconContent, unsigned int lexiconLength, const wchar_t *params, LexiconCallBack callback, void *userData);
  180. #endif
  181. #ifdef __cplusplus
  182. } /* extern "C" */
  183. #endif /* C++ */
  184. #endif /* __QISR_H__ */