speech_recognizer.h 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /*
  2. @file
  3. @brief 基于录音接口和讯飞MSC接口封装一个MIC录音识别的模块
  4. @author taozhang9
  5. @date 2016/05/27
  6. */
  7. enum sr_audsrc
  8. {
  9. SR_MIC, /* write data from mic */
  10. SR_USER /* write data from user by calling API */
  11. };
  12. //#define DEFAULT_INPUT_DEVID (-1)
  13. #define E_SR_NOACTIVEDEVICE 1
  14. #define E_SR_NOMEM 2
  15. #define E_SR_INVAL 3
  16. #define E_SR_RECORDFAIL 4
  17. #define E_SR_ALREADY 5
  18. struct speech_rec_notifier {
  19. void (*on_result)(const char *result, char is_last);
  20. void (*on_speech_begin)();
  21. void (*on_speech_end)(int reason); /* 0 if VAD. others, error : see E_SR_xxx and msp_errors.h */
  22. };
  23. #define END_REASON_VAD_DETECT 0 /* detected speech done */
  24. struct speech_rec {
  25. enum sr_audsrc aud_src; /* from mic or manual stream write */
  26. struct speech_rec_notifier notif;
  27. const char * session_id;
  28. int ep_stat;
  29. int rec_stat;
  30. int audio_status;
  31. struct recorder *recorder;
  32. volatile int state;
  33. char * session_begin_params;
  34. };
  35. #ifdef __cplusplus
  36. extern "C" {
  37. #endif
  38. /* must init before start . is aud_src is SR_MIC, the default capture device
  39. * will be used. see sr_init_ex */
  40. int sr_init(struct speech_rec * sr, const char * session_begin_params, enum sr_audsrc aud_src, struct speech_rec_notifier * notifier);
  41. int sr_start_listening(struct speech_rec *sr);
  42. int sr_stop_listening(struct speech_rec *sr);
  43. /* only used for the manual write way. */
  44. int sr_write_audio_data(struct speech_rec *sr, char *data, unsigned int len);
  45. /* must call uninit after you don't use it */
  46. void sr_uninit(struct speech_rec * sr);
  47. #ifdef __cplusplus
  48. } /* extern "C" */
  49. #endif /* C++ */