lightduer_dcs.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495
  1. /**
  2. * Copyright (2017) Baidu Inc. All rights reserved.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. /**
  17. * File: lightduer_dcs_router.h
  18. * Auth: Gang Chen (chengang12@baidu.com)
  19. * Desc: Light duer DCS APIS.
  20. */
  21. #ifndef BAIDU_DUER_LIGHTDUER_DCS_H
  22. #define BAIDU_DUER_LIGHTDUER_DCS_H
  23. #include "baidu_json.h"
  24. #include "lightduer_types.h"
  25. #ifdef __cplusplus
  26. extern "C" {
  27. #endif
  28. typedef enum {
  29. DCS_PLAY_CMD,
  30. DCS_PAUSE_CMD,
  31. DCS_PREVIOUS_CMD,
  32. DCS_NEXT_CMD,
  33. DCS_PLAY_CONTROL_EVENT_NUMBER,
  34. } duer_dcs_play_control_cmd_t;
  35. typedef enum {
  36. DCS_MEDIA_ERROR_UNKNOWN, // unknown error
  37. // server invalid response, such as bad request, forbidden, not found .etc
  38. DCS_MEDIA_ERROR_INVALID_REQUEST,
  39. DCS_MEDIA_ERROR_SERVICE_UNAVAILABLE, // device cannot connect to server
  40. DCS_MEDIA_ERROR_INTERNAL_SERVER_ERROR, // server failed to handle device's request
  41. DCS_MEDIA_ERROR_INTERNAL_DEVICE_ERROR, // device internal error
  42. } duer_dcs_audio_error_t;
  43. typedef enum {
  44. DCS_RECOMMEND_POWER_ON,
  45. DCS_RECOMMEND_TIME_NUMBER,
  46. } duer_dcs_recommend_time_t;
  47. typedef struct {
  48. const char *url;
  49. int offset;
  50. const char *audio_item_id;
  51. } duer_dcs_audio_info_t;
  52. enum duer_dcs_device_capability {
  53. DCS_TTS_HTTPS_PROTOCAL_SUPPORTED = 0x01, // the device support https protocal to playing tts
  54. DCS_WECHAT_SUPPORTED = 0x02, // the device support wechat
  55. };
  56. /**
  57. * Initialize the dcs framework.
  58. *
  59. * @return none.
  60. */
  61. void duer_dcs_framework_init(void);
  62. /**
  63. * Uninitialize the DCS module.
  64. *
  65. * @return none.
  66. */
  67. void duer_dcs_uninitialize(void);
  68. /**
  69. * DESC:
  70. * Initialize dcs voice input interface.
  71. *
  72. * PARAM: none
  73. *
  74. * @RETURN: none
  75. */
  76. void duer_dcs_voice_input_init(void);
  77. /**
  78. * DESC:
  79. * Notify DCS when recorder start to record.
  80. *
  81. * PARAM: none
  82. *
  83. * @RETURN: 0 when success, negative when fail.
  84. */
  85. int duer_dcs_on_listen_started(void);
  86. /**
  87. * DESC:
  88. * There is no VAD in translate scene,
  89. * hence developer needs to call this function to notify DCS framework after recording finished.
  90. *
  91. * PARAM: none
  92. *
  93. * @RETURN: 0 when success, negative when fail.
  94. */
  95. int duer_dcs_on_listen_stopped(void);
  96. /**
  97. * DESC:
  98. * Developer needs to implement this interface to start recording.
  99. *
  100. * PARAM: none
  101. *
  102. * @RETURN: none.
  103. */
  104. void duer_dcs_listen_handler(void);
  105. /**
  106. * DESC:
  107. * Developer needs to implement this interface to stop recording.
  108. *
  109. * PARAM: none
  110. *
  111. * @RETURN: none.
  112. */
  113. void duer_dcs_stop_listen_handler(void);
  114. /**
  115. * DESC:
  116. * Initialize dcs voice output interface
  117. *
  118. * PARAM: none
  119. *
  120. * @RETURN: none
  121. */
  122. void duer_dcs_voice_output_init(void);
  123. /**
  124. * DESC:
  125. *
  126. * It should be called when speech finished, used to notify DCS level.
  127. *
  128. * PARAM: none
  129. *
  130. * @RETURN: none
  131. */
  132. void duer_dcs_speech_on_finished(void);
  133. /**
  134. * DESC:
  135. * Developer needs to implement this interface to play speech.
  136. *
  137. * PARAM:
  138. * @param[in] url: the url of the speech need to play
  139. *
  140. * @RETURN: none.
  141. */
  142. void duer_dcs_speak_handler(const char *url);
  143. /**
  144. * DESC:
  145. * Developer needs to implement this interface to stop speech.
  146. *
  147. * PARAM:
  148. * @param: none
  149. *
  150. * @RETURN: none.
  151. */
  152. void duer_dcs_stop_speak_handler(void);
  153. /**
  154. * DESC:
  155. * Initialize dcs speaker controler interface to enable volume control function.
  156. *
  157. * PARAM: none
  158. *
  159. * @RETURN: none
  160. */
  161. void duer_dcs_speaker_control_init(void);
  162. /**
  163. * DESC:
  164. * Notify DCS when volume changed
  165. *
  166. * PARAM: none
  167. *
  168. * @RETURN: 0 when success, negative when fail.
  169. */
  170. int duer_dcs_on_volume_changed(void);
  171. /**
  172. * DESC:
  173. * Notify DCS when mute state changed.
  174. *
  175. * PARAM: none
  176. *
  177. * @RETURN: 0 when success, negative when fail.
  178. */
  179. int duer_dcs_on_mute(void);
  180. /**
  181. * DESC:
  182. * Developer needs to implement this interface, it is used to get volume state.
  183. *
  184. * @param[out] volume: current volume value.
  185. * @param[out] is_mute: current mute state.
  186. *
  187. * @RETURN: none.
  188. */
  189. void duer_dcs_get_speaker_state(int *volume, duer_bool *is_mute);
  190. /**
  191. * DESC:
  192. * Developer needs to implement this interface to set volume.
  193. *
  194. * PARAM:
  195. * @param[in] volume: the value of the volume need to set
  196. *
  197. * @RETURN: none.
  198. */
  199. void duer_dcs_volume_set_handler(int volume);
  200. /**
  201. * DESC:
  202. * Developer needs to implement this interface to adjust volume.
  203. *
  204. * PARAM:
  205. * @param[in] volume: the value need to adjusted.
  206. *
  207. * @RETURN: none.
  208. */
  209. void duer_dcs_volume_adjust_handler(int volume);
  210. /**
  211. * DESC:
  212. * Developer needs to implement this interface to change mute state.
  213. *
  214. * PARAM:
  215. * @param[in] is_mute: set/discard mute.
  216. *
  217. * @RETURN: none.
  218. */
  219. void duer_dcs_mute_handler(duer_bool is_mute);
  220. /**
  221. * DESC:
  222. * Initialize dcs audio player interface.
  223. *
  224. * PARAM: none
  225. *
  226. * @RETURN: none
  227. */
  228. void duer_dcs_audio_player_init(void);
  229. /**
  230. * DESC:
  231. * User can also use this API to subscribe FM.
  232. *
  233. * PARAM[in] url: the url identify the FM.
  234. *
  235. * @RETURN: 0 when success, negative when fail.
  236. */
  237. int duer_dcs_on_link_clicked(const char *url);
  238. /**
  239. * DESC:
  240. * Notify DCS when an audio is finished.
  241. *
  242. * PARAM: none
  243. *
  244. * @RETURN: none.
  245. */
  246. void duer_dcs_audio_on_finished(void);
  247. /**
  248. * DESC:
  249. * Notify DCS when failed to play audio.
  250. *
  251. * PARAM[in] type: the error type
  252. * PARAM[in] msg: the error message
  253. *
  254. * @RETURN: 0 when success, negative when fail.
  255. */
  256. int duer_dcs_audio_play_failed(duer_dcs_audio_error_t type, const char *msg);
  257. /**
  258. * DESC:
  259. * Report StreamMetadataExtracted event if metadata is found in the audio.
  260. *
  261. * PARAM[in] metadata: the metadata need to report, its layout is:
  262. * "metadata": {
  263. * "{{STRING}}": "{{STRING}}",
  264. * "{{STRING}}": {{BOOLEAN}}
  265. * "{{STRING}}": "{{STRING NUMBER}}"
  266. * ...
  267. * }
  268. *
  269. * @RETURN: 0 when success, negative when fail.
  270. */
  271. int duer_dcs_audio_report_metadata(baidu_json *metadata);
  272. /**
  273. * DESC:
  274. * Notify DCS when audio is stuttered.
  275. *
  276. * PARAM[in] is_stuttuered: DUER_TRUE when stutter started(download speed lower than play speed),
  277. * DUER_FALSE when stutter finished(the audio resume play).
  278. */
  279. int duer_dcs_audio_on_stuttered(duer_bool is_stuttered);
  280. /**
  281. * DESC:
  282. * Developer needs to implement this interface to play audio.
  283. *
  284. * PARAM:
  285. * @param[in] audio_info: the info of the audio need to play
  286. *
  287. * @RETURN: none.
  288. */
  289. void duer_dcs_audio_play_handler(const duer_dcs_audio_info_t *audio_info);
  290. /**
  291. * DESC:
  292. * Developer needs to implement this interface to stop audio player.
  293. *
  294. * PARAM: none
  295. *
  296. * @RETURN: none.
  297. */
  298. void duer_dcs_audio_stop_handler(void);
  299. /**
  300. * DESC:
  301. * Notify DCS when an audio is stopped not by DCS API.
  302. *
  303. * PARAM: none
  304. *
  305. * @RETURN: none.
  306. */
  307. void duer_dcs_audio_on_stopped(void);
  308. /**
  309. * DESC:
  310. * Developer needs to implement this interface to resume audio play.
  311. *
  312. * PARAM:
  313. * @param[in] audio_info: the info of the audio need to resumed
  314. *
  315. * @RETURN: none.
  316. */
  317. void duer_dcs_audio_resume_handler(const duer_dcs_audio_info_t *audio_info);
  318. /**
  319. * DESC:
  320. * Developer needs to implement this interface to pause audio play.
  321. *
  322. * PARAM: none
  323. *
  324. * @RETURN: none.
  325. */
  326. void duer_dcs_audio_pause_handler(void);
  327. /**
  328. * DESC:
  329. * Developer needs to implement this interface, it's used to get the audio play progress.
  330. *
  331. * PARAM: none
  332. *
  333. * @RETURN: the play position of the audio.
  334. */
  335. int duer_dcs_audio_get_play_progress(void);
  336. /**
  337. * DESC:
  338. * Realize play control(play, pause, next/previous audio) by send command to DCS.
  339. *
  340. * PARAM[in] cmd: command type.
  341. *
  342. * @RETURN: 0 when success, negative when fail.
  343. */
  344. int duer_dcs_send_play_control_cmd(duer_dcs_play_control_cmd_t cmd);
  345. /**
  346. * DESC:
  347. * Report current state after device boot.
  348. *
  349. * PARAM: none
  350. *
  351. * @RETURN: 0 if succuss, negative if failed.
  352. */
  353. int duer_dcs_sync_state(void);
  354. /**
  355. * DESC:
  356. * Sending an "Exited" event to close the multi dialogue.
  357. *
  358. * @RETURN: 0 if succuss, negative if failed.
  359. */
  360. int duer_dcs_close_multi_dialog(void);
  361. /**
  362. * DESC:
  363. * Initialize dcs screen interface.
  364. *
  365. * PARAM: none
  366. *
  367. * @RETURN: none
  368. */
  369. void duer_dcs_screen_init(void);
  370. /**
  371. * DESC:
  372. * Developer needs to implement this interface to get the ASR result.
  373. *
  374. * PARAM[in] text: the ASR text result.
  375. * PARAM[in] type: "INTERMEDIATE" or "FINAL".
  376. *
  377. * @RETURN: DUER_OK if success,
  378. * DUER_MSG_RSP_BAD_REQUEST if the payload is invalid,
  379. * DUER_ERR_FAILED if other error happened.
  380. */
  381. duer_status_t duer_dcs_input_text_handler(const char *text, const char *type);
  382. /**
  383. * DESC:
  384. * Developer needs to implement this interface to get render card.
  385. *
  386. * PARAM[in] payload: the information of the render card, please reference the DCS document.
  387. *
  388. * @RETURN: DUER_OK if success,
  389. * DUER_MSG_RSP_BAD_REQUEST if the payload is invalid,
  390. * DUER_ERR_FAILED if other error happened.
  391. */
  392. duer_status_t duer_dcs_render_card_handler(baidu_json *payload);
  393. /**
  394. * DESC:
  395. * Developer needs to implement this interface to open/close bluetooth.
  396. *
  397. * PARAM[in] is_switch: open bluetooth if is_switch is DUER_TRUE, otherwise close bluetooth.
  398. * PARAM[in] target: Reserved parameter, currently its value is "default".
  399. *
  400. * @RETURN: None
  401. */
  402. void duer_dcs_bluetooth_set_handler(duer_bool is_switch, const char *target);
  403. /**
  404. * DESC:
  405. * Developer needs to implement this interface to connect/disconnect bluetooth to device.
  406. *
  407. * PARAM[in] is_connect: connect bluetooth if is_connect is DUER_TRUE, otherwise disconnect bluetooth.
  408. * PARAM[in] target: Reserved parameter, currently its value is "default".
  409. *
  410. * @RETURN: None
  411. */
  412. void duer_dcs_bluetooth_connect_handler(duer_bool is_connect, const char *target);
  413. /**
  414. * DESC:
  415. * Initialize device control interface, such as control the bluetooth.
  416. *
  417. * PARAM: none
  418. *
  419. * @RETURN: none
  420. */
  421. void duer_dcs_device_control_init(void);
  422. /**
  423. * DESC:
  424. * Used to declare the device capability, such as: whether https or wechat are supported.
  425. * It is unnecessary if the device don't have the capability defined in duer_dcs_device_capability.
  426. * @PARAM[in] capability: the device capability, it's the or value of the member in
  427. * duer_dcs_device_capability.
  428. * @RETURN: DUER_OK if success, negative if failed.
  429. */
  430. duer_status_t duer_dcs_capability_declare(duer_u32_t capability);
  431. /**
  432. * DESC:
  433. * Sending RecommendationRequested event, and DCS server will recommend a resource to device.
  434. * Currently, only the scene of "POWER_ON" is supported, that means this function should be called
  435. * only one time(when device power_on).
  436. *
  437. * @PARAM[in] type: type of the scene.
  438. * @RETURN: 0 if succuss, negative if failed.
  439. */
  440. int duer_dcs_recommend_request(duer_dcs_recommend_time_t time);
  441. #ifdef __cplusplus
  442. }
  443. #endif
  444. #endif/*BAIDU_DUER_LIGHTDUER_DCS_H*/