| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- #include "Util.h"
- #include <chrono>
- #include <sstream>
- #include "tinyxml.h"
-
- /*
- <?xml version="1.0" encoding="utf-8"?>
<result>
- <interpretation grammar="session:hello" confidence="1">
- <instance>
- <result>也不准确。</result>
- <beginTime>2420</beginTime>
- <endTime>3540</endTime>
- <taskId>fba26d3861574ac4b55c01f4881c5bae</taskId>
- <waveformUri>b3f91c673b9146b7-7.wav</waveformUri>
- </instance>
- <input mode="speech">也不准确。</input>
- </interpretation>
- </result>
- */
- bool parseASRXml(const char* desc, std::string& result, std::string& error)
- {
- try{
- TiXmlDocument doc;
- doc.Parse(desc);
- auto pRoot = doc.RootElement();
- if (pRoot != nullptr && pRoot->ValueStr() == "result") {
- auto pElement = pRoot->FirstChildElement("interpretation");
- if (pElement) {
- auto pInput = pElement->FirstChildElement("input");
- if (pInput) {
- auto pText = pInput->GetText();
- result = pText != nullptr ? pText : "";
- return true;
- }
- }
- }
- }
- catch (const std::exception& e){
- error = e.what();
- }
- return false;
- }
-
- int64_t GetUnixTime()
- {
- int64_t times = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch()).count();
- return times;
- }
-
- std::string std::to_string(const char * src)
- {
- if (src == nullptr)return "";
- std::stringstream ss;
- ss << src;
- std::string str;
- ss >> str;
- return str;
- }
|