ql_api_tts.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317
  1. 
  2. /*================================================================
  3. Copyright (c) 2021, Quectel Wireless Solutions Co., Ltd. All rights reserved.
  4. Quectel Wireless Solutions Proprietary and Confidential.
  5. =================================================================*/
  6. /**
  7. @file
  8. ql_api_tts.h
  9. @brief
  10. This file provides the definitions for tts API functions.
  11. */
  12. /*=================================================================
  13. EDIT HISTORY FOR MODULE
  14. This section contains comments describing changes made to the module.
  15. Notice that changes are listed in reverse chronological order.
  16. WHEN WHO WHAT, WHERE, WHY
  17. ------------ ------- -------------------------------------------------------------------------------
  18. =================================================================*/
  19. #ifndef QL_API_TTS_H
  20. #define QL_API_TTS_H
  21. #include "ql_api_common.h"
  22. #ifdef __cplusplus
  23. extern "C" {
  24. #endif
  25. #ifdef CONFIG_QUEC_PROJECT_FEATURE_TTS
  26. #define TTS_DIGIT_AUTO 0
  27. #define TTS_DIGIT_NUMBER 1
  28. #define TTS_DIGIT_VALUE 2
  29. /*===========================================================================
  30. * Macro Definition
  31. ===========================================================================*/
  32. /*===========================================================================
  33. * Enum
  34. ===========================================================================*/
  35. typedef enum
  36. {
  37. QL_TTS_SUCCESS = QL_SUCCESS,
  38. QL_TTS_UNKNOWN_ERROR = 901 | (QL_COMPONENT_AUDIO_TTS << 16),
  39. QL_TTS_INVALID_PARAM = 902 | (QL_COMPONENT_AUDIO_TTS << 16),
  40. QL_TTS_OPERATION_NOT_SUPPORT = 903 | (QL_COMPONENT_AUDIO_TTS << 16),
  41. QL_TTS_DEVICE_BUSY = 904 | (QL_COMPONENT_AUDIO_TTS << 16),
  42. QL_TTS_NO_MEMORY = 905 | (QL_COMPONENT_AUDIO_TTS << 16),
  43. QL_TTS_RESOURCE_WAIT_MERGE = 906 | (QL_COMPONENT_AUDIO_TTS << 16),
  44. QL_TTS_INIT_ENGINE_ERR = 2001 | (QL_COMPONENT_AUDIO_TTS << 16),
  45. QL_TTS_INIT_SOURCE_ERR = 2002 | (QL_COMPONENT_AUDIO_TTS << 16),
  46. QL_TTS_START_ERR = 2003 | (QL_COMPONENT_AUDIO_TTS << 16),
  47. QL_TTS_STOP_ERR = 2004 | (QL_COMPONENT_AUDIO_TTS << 16),
  48. QL_TTS_EXIT_ERR = 2005 | (QL_COMPONENT_AUDIO_TTS << 16),
  49. QL_TTS_SOURCE_NOT_EXIST = 2006 | (QL_COMPONENT_AUDIO_TTS << 16), //tts source not exist, please re-import the TTS resource file: "SFS:quectel_pcm_resource.bin"
  50. QL_TTS_SOURCE_ERROR = 2007 | (QL_COMPONENT_AUDIO_TTS << 16), //tts source error, please re-import the TTS resource file
  51. QL_TTS_LIB_EXPIRED = 2008 | (QL_COMPONENT_AUDIO_TTS << 16), //tts lib too old, please contact us to change the library
  52. QL_TTS_DEVICE_ID_ERROR = 2009 | (QL_COMPONENT_AUDIO_TTS << 16), //chip id is error
  53. }ql_errcode_tts_e;
  54. typedef enum
  55. {
  56. QL_TTS_CONFIG_SPEED = 1,
  57. QL_TTS_CONFIG_VOLUME,
  58. QL_TTS_CONFIG_ENCODING,
  59. QL_TTS_CONFIG_DIGITS,
  60. QL_TTS_CONFIG_DGAIN,
  61. QL_TTS_CONFIG_MAX,
  62. }ql_tts_config_e;
  63. typedef enum
  64. {
  65. QL_TTS_GBK=0,
  66. QL_TTS_UTF8,
  67. QL_TTS_UCS2,
  68. QL_TTS_ENCODE_MAX
  69. }ql_tts_encoding_e;
  70. typedef enum
  71. {
  72. TTS_RESOURCE_16K_CN = 1,
  73. TTS_RESOURCE_16K_EN,
  74. TTS_RESOURCE_8K_CN
  75. }TTS_RESOURCE_E;
  76. typedef enum
  77. {
  78. /*
  79. tts resource file is in internal flash, should be prepacked as /qsfs/quectel_pcm_resource.bin
  80. after prepacked done, users can use ql_stat("SFS:quectel_pcm_resource.bin",st)
  81. to check if the tts resource file is exist
  82. */
  83. POSIT_INTERNAL_FS = 0,
  84. /*
  85. tts resource file is in external spi6 flash, should be prepacked as /ext/qsfs/quectel_pcm_resource.bin
  86. after prepacked done, users can use ql_stat("EFS:qsfs/quectel_pcm_resource.bin",st)
  87. to check if the tts resource file is exist
  88. */
  89. POSIT_EFS,
  90. /*
  91. tts resource file is in external spi4 flash, should be prepacked as /ext4n/qsfs/quectel_pcm_resource.bin
  92. after prepacked done, users can use ql_stat("EXNSFFS:qsfs/quectel_pcm_resource.bin",st)
  93. to check if the tts resource file is exist
  94. */
  95. POSIT_EXNSFFS
  96. }TTS_POSITION_E;
  97. /*===========================================================================
  98. * Variate
  99. ===========================================================================*/
  100. typedef struct
  101. {
  102. int ql_tts_volume; // play volume
  103. int ql_tts_speed; // play speed
  104. int ql_tts_encoding_type; // utf8 , gbk,ucs2
  105. int ql_tts_running_flag;
  106. int ql_tts_readdigit;//0:TTS_DIGIT_AUTO, 1:TTS_DIGIT_NUMBER, 2:TTS_DIGIT_VALUE
  107. uint8 language; //TTS_LANGUAGE_CHINESE or TTS_LANGUAGE_ENGLISH
  108. char *prepack_path;
  109. int ql_tts_dgain; // volume gain
  110. }ql_tts_typeconfig_t;
  111. typedef struct
  112. {
  113. TTS_RESOURCE_E resource; //chose to use 16k_chinese, 16k english, or 8k chinese reource
  114. TTS_POSITION_E position; //chose to prepack tts resource to internal flash or external flash
  115. uint8 reserve[1];
  116. }tts_param_t;
  117. /*===========================================================================
  118. * Functions
  119. ===========================================================================*/
  120. /*****************************************************************
  121. * Function: ql_utf8_to_gbk_str
  122. *
  123. * Description: tts data utf-8 to gbk
  124. *
  125. * Parameters:
  126. * Return:
  127. * 0: success
  128. others: ql_errcode_tts_e
  129. *****************************************************************/
  130. ql_errcode_tts_e ql_utf8_to_gbk_str(void * utf8, int inputlen, int * outputlen,void * gbk);
  131. /*****************************************************************
  132. * Function: pUserCallback
  133. *
  134. * Description: tts data callback, pcm data will be sent to this callback
  135. *
  136. * Parameters:
  137. * param4: PCM data buffer
  138. * Return:
  139. * config value
  140. *****************************************************************/
  141. typedef int (*pUserCallback)(void *param, int param1, int param2, int param3, int data_len, const void *pcm_data);
  142. /*****************************************************************
  143. * Function: ql_tts_get_config_param
  144. *
  145. * Description: get the tts param value
  146. *
  147. * Parameters:
  148. * type: speed, volume, volume dgain, or encoding,
  149. volume range is -32768~32767, and 0 is default;
  150. speed range is -32768~32767, and 0 is default
  151. encoding : QL_TTS_GBK, QL_TTS_UTF8, QL_TTS_UCS2, and QL_TTS_GBK is default
  152. readdigit : 0:TTS_DIGIT_AUTO, 1:TTS_DIGIT_NUMBER, 2:TTS_DIGIT_VALUE, and TTS_DIGIT_VALUE is default
  153. volume dgain range is 0~4,and 0 is default
  154. * Return:
  155. * config value
  156. *****************************************************************/
  157. int ql_tts_get_config_param(ql_tts_config_e type);
  158. /*****************************************************************
  159. * Function: ql_tts_is_running
  160. *
  161. * Description: get the tts state
  162. *
  163. * Parameters:
  164. * Return:
  165. * 0: tts is not running
  166. 1: tts is running
  167. *****************************************************************/
  168. int ql_tts_is_running(void);
  169. /*****************************************************************
  170. * Function: ql_tts_set_config_param
  171. *
  172. * Description: set the tts param value, it will take effect in next play duration
  173. *
  174. * Parameters:
  175. * type: speed, volume, volume dgain, or encoding,
  176. volume range is -32768~32767, and 0 is default;
  177. speed range is -32768~32767, and 0 is default
  178. encoding : QL_TTS_GBK, QL_TTS_UTF8, QL_TTS_UCS2, and QL_TTS_GBK is default
  179. readdigit : 0:TTS_DIGIT_AUTO, 1:TTS_DIGIT_NUMBER, 2:TTS_DIGIT_VALUE, and TTS_DIGIT_VALUE is default
  180. volume dgain range is 0~4,and 0 is default
  181. value: the config value need to be set
  182. * Return:
  183. * 0: success
  184. others: ql_errcode_tts_e
  185. *****************************************************************/
  186. ql_errcode_tts_e ql_tts_set_config_param(ql_tts_config_e type, int value)
  187. ;
  188. /*****************************************************************
  189. * Function: ql_tts_engine_init
  190. *
  191. * Description: init tts, use Chinese 16k tts resource, and tts resource prepacked in internal flash
  192. *
  193. * Parameters:
  194. * mCallback: play callback, text will be convert to 16-bit pcm data, and the pcm data
  195. will be sent to this callback, see descreption of pUserCallback in detail
  196. * Return:
  197. * 0: success
  198. others: ql_errcode_tts_e
  199. *note: chinese resource need be prepacked in file system firstly
  200. if return QL_TTS_INIT_ENGINE_ERR, see if the file "SFS:quectel_pcm_resource.bin"
  201. is exist in file system, and if the ram is enough; tts playing need at least 620k ram
  202. *****************************************************************/
  203. ql_errcode_tts_e ql_tts_engine_init(pUserCallback mCallback);
  204. /*****************************************************************
  205. * Function: ql_tts_engine_init_ex
  206. *
  207. * Description: init tts, user can choose tts resource by this api. If not use Chinses 16k reource, or
  208. prepacked tts resource in external flash, users need to aujust the prepack json, can see
  209. it in tts_demo.c or tts_demo2.c for detail
  210. *
  211. * Parameters:
  212. * mCallback: play callback, text will be convert to 16-bit pcm data, and the pcm data
  213. will be sent to this callback, see descreption of pUserCallback in detail
  214. * param->resource: choose to use chinese-16k, chinese-8k, or english-16k tts resource, default use chinese-16k
  215. * param->position: tell the prepack path to kernel, kernel will use the prepack path to initial tts, default
  216. path is internal flash
  217. *
  218. * Return:
  219. * 0: success
  220. others: ql_errcode_tts_e
  221. *note: chinese resource or english resource need be prepacked in file system firstly if not return 0, see
  222. 1. if the file "SFS:quectel_pcm_resource.bin"(prepacked to internal flash),or
  223. "EFS:qsfs/quectel_pcm_resource.bin"(prepacked to external spi6 flash)is exist in file system
  224. 2. if the ram is enough; tts playing need at least 620k ram if use chinese-16k resource,
  225. need at least 1.45M ram if use english resource , and need at least 570k ram if use chinese-8k resource
  226. *****************************************************************/
  227. ql_errcode_tts_e ql_tts_engine_init_ex(pUserCallback mCallback, tts_param_t *param);
  228. /*****************************************************************
  229. * Function: ql_tts_start
  230. *
  231. * Description: start tts convert,encoding support GBK, UCS2, UTF8 now, default GBK
  232. before play tts, you should set encoding first
  233. *
  234. * Parameters:
  235. * textString: the text need to be convert, format should be GBK, UCS2 or UTF8
  236. * textLen: the length of text
  237. * Return:
  238. * 0: success
  239. others: ql_errcode_tts_e
  240. *****************************************************************/
  241. ql_errcode_tts_e ql_tts_start(const char* textString, unsigned int textLen);
  242. /*****************************************************************
  243. * Function: ql_tts_end
  244. *
  245. * Description: stop tts convert, and release some tts resource
  246. *
  247. * Parameters:
  248. * Return:
  249. * 0: success
  250. others: ql_errcode_tts_e
  251. *****************************************************************/
  252. ql_errcode_tts_e ql_tts_end();
  253. /*****************************************************************
  254. * Function: ql_tts_exit
  255. *
  256. * Description: interrupt tts convert
  257. *
  258. * Parameters:
  259. * Return:
  260. * 0: success
  261. others: ql_errcode_tts_e
  262. *****************************************************************/
  263. ql_errcode_tts_e ql_tts_exit();
  264. #endif
  265. #ifdef __cplusplus
  266. } /*"C" */
  267. #endif
  268. #endif /* QL_API_TTS_H*/