Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Text:Update Text Interface 1.6 spec #764

Merged
merged 1 commit into from
Dec 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion src/capability/asr_agent.cc
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,8 @@ void ASRAgent::sendEventRecognize(unsigned char* data, size_t length, bool is_en
{
Json::FastWriter writer;
Json::Value root;
std::string payload = "";
std::string payload;
std::string et_attr;

if (!rec_event) {
nugu_error("recognize event is not created");
Expand All @@ -409,6 +410,8 @@ void ASRAgent::sendEventRecognize(unsigned char* data, size_t length, bool is_en
root["domainTypes"] = es_attr.domain_types;
if (!es_attr.asr_context.empty())
root["asrContext"] = es_attr.asr_context;
} else if (capa_helper->getCapabilityProperty("Text", "et.attributes", et_attr) && !et_attr.empty()) {
setExpectTypingAttributes(root, std::move(et_attr));
} else {
// reset referrer dialog request id
setReferrerDialogRequestId("ExpectSpeech", "");
Expand Down Expand Up @@ -836,6 +839,19 @@ bool ASRAgent::isExpectSpeechState()
return es_attr.is_handle;
}

void ASRAgent::setExpectTypingAttributes(Json::Value& root, std::string&& et_attr)
{
Json::Value et_attr_json;
Json::Reader reader;

if (!reader.parse(et_attr, et_attr_json))
return;

for (const auto& key : { "playServiceId", "domainTypes", "asrContext" })
if (et_attr_json.isMember(key))
root[key] = et_attr_json[key];
}

ASRAgent::FocusListener::FocusListener(ASRAgent* asr_agent, IFocusManager* focus_manager, bool asr_user)
: asr_agent(asr_agent)
, focus_manager(focus_manager)
Expand Down
1 change: 1 addition & 0 deletions src/capability/asr_agent.hh
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ private:
ASRState getASRState();
void resetExpectSpeechState();
bool isExpectSpeechState();
void setExpectTypingAttributes(Json::Value& root, std::string&& et_attr);

class FocusListener : public IFocusResourceListener {
public:
Expand Down
52 changes: 28 additions & 24 deletions src/capability/text_agent.cc
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,23 @@ void TextAgent::receiveCommandAll(const std::string& command, const std::string&
}
}

bool TextAgent::getProperty(const std::string& property, std::string& value)
{
value.clear();

if (property == "et.attributes") {
if (expect_typing.is_handle) {
Json::FastWriter writer;
value = writer.write(expect_typing.payload);
}
} else {
nugu_error("invalid property: %s", property.c_str());
return false;
}

return true;
}

void TextAgent::setCapabilityListener(ICapabilityListener* clistener)
{
if (clistener)
Expand Down Expand Up @@ -247,24 +264,23 @@ void TextAgent::sendEventTextInput(const TextInputParam& text_input_param, bool
if (!text_input_param.ps_id.empty())
root["playServiceId"] = text_input_param.ps_id;
else if (include_dialog_attribute) {
auto composeDialogAttribute = [&](const std::string& ps_id, const std::list<std::string>& domain_types) {
if (!ps_id.empty())
root["playServiceId"] = ps_id;

for (const auto& domain_type : domain_types)
if (!domain_type.empty())
root["domainTypes"].append(domain_type);
};

if (expect_typing.is_handle) {
composeDialogAttribute(expect_typing.ps_id, expect_typing.domain_types);
for (const auto& key : { "playServiceId", "domainTypes" })
if (expect_typing.payload.isMember(key))
root[key] = expect_typing.payload[key];
} else {
std::string ps_id = "";
std::list<std::string> domain_types;

capa_helper->getCapabilityProperty("ASR", "es.playServiceId", ps_id);
capa_helper->getCapabilityProperties("ASR", "es.domainTypes", domain_types);
composeDialogAttribute(ps_id, domain_types);

if (!ps_id.empty())
root["playServiceId"] = ps_id;

for (const auto& domain_type : domain_types)
if (!domain_type.empty())
root["domainTypes"].append(domain_type);
}
}

Expand Down Expand Up @@ -366,20 +382,8 @@ void TextAgent::parsingExpectTyping(const char* message)
}

expect_typing.is_handle = true;
expect_typing.ps_id = root["playServiceId"].asString();
expect_typing.playstack = cur_playstack;

if (root.isMember("domainTypes")) {
const Json::Value domain_types = root["domainTypes"];
Json::ArrayIndex domain_types_count = domain_types.size();

for (Json::ArrayIndex i = 0; i < domain_types_count; i++) {
std::string domain_type = domain_types[i].asString();

if (!domain_type.empty())
expect_typing.domain_types.emplace_back(domain_type);
}
}
expect_typing.payload.swap(root);
}

bool TextAgent::handleTextCommonProcess(const TextInputParam& text_input_param)
Expand Down
4 changes: 2 additions & 2 deletions src/capability/text_agent.hh
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public:
void parsingDirective(const char* dname, const char* message) override;
void updateInfoForContext(Json::Value& ctx) override;
void receiveCommandAll(const std::string& command, const std::string& param) override;
bool getProperty(const std::string& property, std::string& value) override;
void setCapabilityListener(ICapabilityListener* clistener) override;

std::string requestTextInput(const std::string& text, const std::string& token = "", bool include_dialog_attribute = true) override;
Expand All @@ -57,8 +58,7 @@ private:
using ExpectTypingInfo = struct {
bool is_handle = false;
std::string playstack;
std::string ps_id;
std::list<std::string> domain_types;
Json::Value payload;
};

std::string requestTextInput(TextInputParam&& text_input_param, bool routine_play, bool include_dialog_attribute = true);
Expand Down