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

Adding setLanguage at runtime #36

Merged
merged 8 commits into from
May 20, 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
1 change: 1 addition & 0 deletions speechInteraction/modules/googleDialog/app/conf/config.ini
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
name googleDialog
language_code en-US
sample_rate_hertz 16000
languageCodes en-US it-IT pt-PT fr-FR en-GB
16 changes: 15 additions & 1 deletion speechInteraction/modules/googleDialog/googleDialog.thrift
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,19 @@ service googleDialog_IDL
* Reset the conversation.
*/
bool resetDialog();

/**
* Set the language of the synthesiser.
* example: setLanguage en-US
* @param string containing the languageCode
* @return true/false on success/failure
*/
bool setLanguage(1:string languageCode);

/**
* Get the language code of the synthesiser
* @return string containing the language code
*/
string getLanguageCode();

}
}
50 changes: 50 additions & 0 deletions speechInteraction/modules/googleDialog/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,19 @@ class Processing : public yarp::os::BufferedPort<yarp::os::Bottle>
return result;
}

/********************************************************/
bool setLanguageCode(const std::string &languageCode)
{
language_code = languageCode;
return true;
}

/********************************************************/
std::string getLanguageCode()
{
return language_code;
}

/********************************************************/
bool start_acquisition()
{
Expand Down Expand Up @@ -254,6 +267,7 @@ class Module : public yarp::os::RFModule, public googleDialog_IDL
friend class processing;

bool closing;
std::vector<std::string> allLanguageCodes;

/********************************************************/
bool attach(yarp::os::RpcServer &source)
Expand All @@ -274,6 +288,15 @@ class Module : public yarp::os::RFModule, public googleDialog_IDL
std::string agent_name = rf.check("agent", yarp::os::Value("1"), "name of the agent").asString();
std::string language_code = rf.check("language", yarp::os::Value("en-US"), "language of the dialogflow").asString();

if (rf.check("languageCodes", "Getting language codes"))
{
yarp::os::Bottle &grp=rf.findGroup("languageCodes");
int sz=grp.size()-1;

for (int i=0; i<sz; i++)
allLanguageCodes.push_back(grp.get(1+i).asString());
}

yDebug() << "this is the project" << rf.check("project");
yDebug() << "Module name" << moduleName;
yDebug() << "agent name" << agent_name;
Expand All @@ -295,6 +318,33 @@ class Module : public yarp::os::RFModule, public googleDialog_IDL
return true;
}

/********************************************************/
bool setLanguage(const std::string& languageCode)
{
bool returnVal = false;

std::string language;

for (int i = 0; i < allLanguageCodes.size(); i++)
{
if (languageCode == allLanguageCodes[i])
{
language = languageCode;
processing->setLanguageCode(languageCode);
returnVal = true;
break;
}
}

return returnVal;
}

/********************************************************/
std::string getLanguageCode()
{
return processing->getLanguageCode();
}

/**********************************************************/
bool close()
{
Expand Down
1 change: 1 addition & 0 deletions speechInteraction/modules/googleSpeech/app/conf/config.ini
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
name googleSpeech
language_code en-US
sample_rate_hertz 16000
languageCodes en-US it-IT pt-PT fr-FR en-GB
14 changes: 14 additions & 0 deletions speechInteraction/modules/googleSpeech/googleSpeech.thrift
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,18 @@ service googleSpeech_IDL
* @return a double containing the processing time
*/
i64 getProcessingTime();

/**
* Set the language of the synthesiser.
* example: setLanguage en-US
* @param string containing the languageCode
* @return true/false on success/failure
*/
bool setLanguage(1:string languageCode);

/**
* Get the language code of the synthesiser
* @return string containing the language code
*/
string getLanguageCode();
}
53 changes: 52 additions & 1 deletion speechInteraction/modules/googleSpeech/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,19 @@ class Processing : public yarp::os::TypedReaderCallback<yarp::sig::Sound>
return b;
}

/********************************************************/
bool setLanguageCode(const std::string &languageCode)
{
language = languageCode;
return true;
}

/********************************************************/
std::string getLanguageCode()
{
return language;
}

/********************************************************/
void setArguments(RecognitionConfig* config)
{
Expand Down Expand Up @@ -348,6 +361,7 @@ class Module : public yarp::os::RFModule, public googleSpeech_IDL

bool closing;
bool uniqueSound;
std::vector<std::string> allLanguageCodes;

/********************************************************/
bool attach(yarp::os::RpcServer &source)
Expand All @@ -372,6 +386,15 @@ class Module : public yarp::os::RFModule, public googleSpeech_IDL
if (rf.check("uniqueSound", "use a yarp::sig::Sound instead of a microphone"))
uniqueSound = true;

if (rf.check("languageCodes", "Getting language codes"))
{
yarp::os::Bottle &grp=rf.findGroup("languageCodes");
int sz=grp.size()-1;

for (int i=0; i<sz; i++)
allLanguageCodes.push_back(grp.get(1+i).asString());
}

setName(moduleName.c_str());

rpcPort.open(("/"+getName("/rpc")).c_str());
Expand All @@ -392,6 +415,34 @@ class Module : public yarp::os::RFModule, public googleSpeech_IDL
return true;
}

/********************************************************/
bool setLanguage(const std::string& languageCode)
{
bool returnVal = false;

std::string language;

for (int i = 0; i < allLanguageCodes.size(); i++)
{
if (languageCode == allLanguageCodes[i])
{
language = languageCode;
processing->setLanguageCode(languageCode);
returnVal = true;
break;
}
}

return returnVal;
}

/********************************************************/
std::string getLanguageCode()
{
return processing->getLanguageCode();
}


/**********************************************************/
bool close()
{
Expand Down Expand Up @@ -477,4 +528,4 @@ int main(int argc, char *argv[])
rf.configure(argc,argv);

return module.runModule(rf);
}
}