linux版本中间件

AsrInfo.cpp 1.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. #include "AsrInfo.h"
  2. #include "Util.h"
  3. #include <json/json.h>
  4. AsrInfo::AsrInfo()
  5. {
  6. __reset();
  7. }
  8. AsrInfo::~AsrInfo()
  9. {
  10. __reset();
  11. }
  12. void AsrInfo::setCallInfo(const std::string&strCallID,const std::string & strCaller, const std::string & strCalled, const std::string & strDirection, const std::string & strVocDirect)
  13. {
  14. callStartTime = GetUnixTime();
  15. callID = strCallID;
  16. caller = strCaller;
  17. called = strCalled;
  18. direction = strDirection;
  19. vocDirect = strVocDirect;
  20. }
  21. void AsrInfo::setSentenceBeginTime()
  22. {
  23. sentenceBeginTime = GetUnixTime() - callStartTime;
  24. }
  25. void AsrInfo::setTransSentenceText(const std::string&strTransText, const std::int32_t&nIndex)
  26. {
  27. createTime = GetUnixTime();
  28. transSentenceTime = createTime - callStartTime;
  29. transSentenceText = strTransText;
  30. transSentenceIndex = nIndex;
  31. }
  32. std::string AsrInfo::asrInfo()
  33. {
  34. Json::Value root;
  35. root["callID"] = callID;
  36. root["callStartTime"] = callStartTime;
  37. root["agent"] = agent;
  38. root["caller"] = caller;
  39. root["called"] = called;
  40. root["direction"] = direction;
  41. root["vocDirect"] = vocDirect;
  42. root["sentenceBeginTime"] = sentenceBeginTime;
  43. root["createTime"] = createTime;
  44. root["transSentenceTime"] = transSentenceTime;
  45. root["transSentenceText"] = transSentenceText;
  46. root["transSentenceIndex"] = transSentenceIndex;
  47. Json::StreamWriterBuilder builder;
  48. return Json::writeString(builder, root);
  49. }
  50. void AsrInfo::__reset()
  51. {
  52. callID = "";
  53. callStartTime = 0;
  54. caller = "";
  55. called = "";
  56. direction = "";
  57. vocDirect = "";
  58. createTime = 0;
  59. sentenceBeginTime = 0;
  60. transSentenceText = "";
  61. transSentenceIndex = 0;
  62. transSentenceTime = 0;
  63. }