WaitTTS(BatchExecutor *executor, std::chrono::milliseconds timeout, std::string pattern)
: PredicateWaitInterface(executor, timeout)
{
- std::regex regex;
- if (!pattern.empty()) {
- try {
- regex = std::regex {
- pattern,
- std::regex_constants::nosubs |
- std::regex_constants::optimize |
- std::regex_constants::ECMAScript
- };
- } catch (...) {
- throw EvaluationFailure{} << "invalid regex pattern '" << pattern << "'";
- }
- }
{
auto h = self->ttsInfo.lock();
if (!pattern.empty())
- h->searchLine = std::move(regex);
+ h->searchLine = std::move(pattern);
h->mode = BatchExecutor::TTSInfo::Mode::search;
}
this->pattern = std::move(pattern);
});
}
if (hasContext) {
- auto ttsMainRegex = std::regex {
- "^D/SCREEN-READER[^>]*?> READ COMMAND PARAMS, TEXT: (.*?), DISCARDABLE: 0",
- std::regex_constants::optimize | std::regex_constants::ECMAScript
- };
- auto ttsDlogHandler = dlog.registerCallback([&exec, ttsMainRegex = std::move(ttsMainRegex)](const std::string & txt) {
+ auto ttsDlogHandler = dlog.registerCallback([&exec](const std::string & txt) {
auto h = exec->ttsInfo.lock();
if (h->mode == BatchExecutor::TTSInfo::Mode::search) {
if (!h->searchLine) {
h->mode = BatchExecutor::TTSInfo::Mode::found;
} else {
- std::smatch result;
- if (std::regex_search(txt, result, ttsMainRegex)) {
- auto sub = result[1].str();
- if (std::regex_search(sub, *h->searchLine))
- h->mode = BatchExecutor::TTSInfo::Mode::found;
+ if (txt.find("(tts_speak_do)") != std::string::npos) {
+ auto z = txt.rfind(", text ");
+ if (z != std::string::npos) {
+ z += 7;
+ auto z2 = txt.rfind("))");
+ if (z2 != std::string::npos) {
+ auto sub = txt.substr(z, z2 - z);
+ exec->outputStream() << "TTS: '" << sub << "'\n";
+ if (sub.find(*h->searchLine) != std::string::npos) {
+ h->mode = BatchExecutor::TTSInfo::Mode::found;
+ }
+ }
+ }
}
}
}