You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

42 lines
1.3 KiB

  1. #include "asr_service.hpp"
  2. #include "zlinuxcomponents/aiui_ws/aiui.h"
  3. using namespace iflytop;
  4. using namespace core;
  5. using namespace std;
  6. static AiuiService *thisClass = nullptr;
  7. void aiui_message_cb(const char *data, int len) {
  8. if (thisClass) {
  9. thisClass->call_aiui_message_cb(data, len);
  10. }
  11. }
  12. void aiui_error_cb(int code, const char *str) {
  13. if (thisClass) {
  14. thisClass->call_aiui_error_cb(code, str);
  15. }
  16. }
  17. AiuiService::AiuiService() { thisClass = this; }
  18. int AiuiService::aiuiInit(const char *appid, const char *key, const char *param) {
  19. thisClass = this;
  20. return aiui_init(appid, key, param, aiui_message_cb, aiui_error_cb);
  21. }
  22. int AiuiService::aiuiWrite(const char *audio, int len) { return aiui_write(audio, len); }
  23. int AiuiService::aiuiFinished() { return aiui_finished(); }
  24. void AiuiService::aiuiDestroy() {
  25. aiui_destroy();
  26. thisClass = nullptr;
  27. }
  28. void AiuiService::call_aiui_message_cb(const char *data, int len) {
  29. try {
  30. json j = json::parse(data);
  31. onAsrResult(j);
  32. } catch (const std::exception &e) {
  33. logger->error("AiuiService::call_aiui_message_cb error: {}", e.what());
  34. }
  35. }
  36. void AiuiService::call_aiui_error_cb(int code, const char *str) {
  37. logger->error("AiuiService::call_aiui_error_cb error: {} => {}", code, str);
  38. onError(code, str);
  39. }