Path: blob/master/examples/cpptflite/src/TTSFrontend.cpp
1559 views
#include "TTSFrontend.h"12void TTSFrontend::text2ids(const std::string &text)3{4_phonesIds = strSplit(getCmdResult(text));5}67std::string TTSFrontend::getCmdResult(const std::string &text)8{9char buf[1000] = {0};10FILE *pf = NULL;1112if( (pf = popen((_strCmd + " " + _mapperJson + " \"" + text + "\"").c_str(), "r")) == NULL )13{14return "";15}1617while(fgets(buf, sizeof(buf), pf))18{19continue;20}2122std::string strResult(buf);23pclose(pf);2425return strResult;26}2728std::vector<int32_t> TTSFrontend::strSplit(const std::string &idStr)29{30std::vector<int32_t> idsVector;3132std::regex rgx ("\\s+");33std::sregex_token_iterator iter(idStr.begin(), idStr.end(), rgx, -1);34std::sregex_token_iterator end;3536while (iter != end) {37idsVector.push_back(stoi(*iter));38++iter;39}4041return idsVector;42}4344